Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph.externalNodes is Empty When Using Webpack with Bun, Causing Build Failures #30466

Open
1 of 4 tasks
lwensveen opened this issue Mar 23, 2025 · 0 comments
Open
1 of 4 tasks
Assignees
Labels
scope: bundlers Issues related to webpack, rollup type: bug

Comments

@lwensveen
Copy link

lwensveen commented Mar 23, 2025

Current Behavior

Description

When using webpack with Bun as the package manager in an Nx workspace, the build fails with the error:

NX Cannot read properties of undefined (reading 'data')

This occurs because graph.externalNodes is empty ({}), meaning Nx is not registering external dependencies like tslib in the dependency graph. Switching to esbuild resolves the issue, indicating that the problem is specific to webpack.

Actual Behavior

The build fails with the error:

NX Cannot read properties of undefined (reading 'data')

Logs show that graph.externalNodes is empty:

Graph External Nodes: []

Broken project.json config

{
  "name": "api",
  "$schema": "../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "api/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "platform": "node",
        "outputPath": "dist/api",
        "format": ["cjs"],
        "bundle": false,
        "main": "api/src/main.ts",
        "tsConfig": "api/tsconfig.app.json",
        "assets": ["api/src/assets"],
        "webpackConfig": "api/webpack.config.js",
        "generatePackageJson": true,
        "esbuildOptions": {
          "sourcemap": true,
          "outExtension": {
            ".js": ".js"
          }
        }
      },
      "configurations": {
        "development": {},
        "production": {
          "esbuildOptions": {
            "sourcemap": false,
            "outExtension": {
              ".js": ".js"
            }
          }
        }
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "dependsOn": ["build"],
      "options": {
        "buildTarget": "api:build",
        "runBuildTargetDependencies": false
      },
      "configurations": {
        "development": {
          "buildTarget": "api:build:development"
        },
        "production": {
          "buildTarget": "api:build:production"
        }
      }
    },
    "test": {
      "options": {
        "passWithNoTests": true
      }
    }
  }
}

Additional Context

  • The issue does not occur when using esbuild instead of webpack. Here’s the working project.json configuration for esbuild:

    {
      "build": {
        "executor": "@nx/esbuild:esbuild",
        "options": {
          "platform": "node",
          "outputPath": "dist/apps/test-api",
          "format": ["cjs"],
          "bundle": false,
          "main": "apps/test-api/src/main.ts",
          "tsConfig": "apps/test-api/tsconfig.app.json",
          "assets": ["apps/test-api/src/assets"],
          "generatePackageJson": true,
          "esbuildOptions": {
            "sourcemap": true,
            "outExtension": {
              ".js": ".js"
            }
          }
        }
      }
    }
  • The issue appears to be related to how Nx integrates with webpack when using Bun as the package manager.

Expected Behavior

Expected Behavior

The build should succeed, and graph.externalNodes should include tslib.

GitHub Repo

https://github.com/lwensveen/nx-examples/tree/webpack-error-generate-packagejson

Steps to Reproduce

Steps to Reproduce

  1. Clone the repository:
    git clone https://github.com/your-username/repro-nx-bun-issue.git
    cd repro-nx-bun-issue
  2. Install dependencies:
    bun install
  3. Run the build with webpack:
    nx run-many --target=build --all --verbose

Nx Report

Node           : 20.19.0
OS             : darwin-arm64
Native Target  : aarch64-macos
bun            : 1.2.5

nx (global)            : 20.6.2
nx                     : 20.6.2
@nx/js                 : 20.6.2
@nx/jest               : 20.6.2
@nx/eslint             : 20.6.2
@nx/workspace          : 20.6.2
@nx/angular            : 20.6.2
@nx/cypress            : 20.6.2
@nx/devkit             : 20.6.2
@nx/esbuild            : 20.6.2
@nx/eslint-plugin      : 20.6.2
@nx/module-federation  : 20.6.2
@nx/node               : 20.6.2
@nx/react              : 20.6.2
@nx/rspack             : 20.6.2
@nx/web                : 20.6.2
@nx/webpack            : 20.6.2
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/cypress/plugin
@nx/jest/plugin
---------------------------------------
Community plugins:
@ngrx/component-store : 19.0.0
@ngrx/effects         : 19.0.0
@ngrx/entity          : 19.0.0
@ngrx/operators       : 19.0.0
@ngrx/router-store    : 19.0.0
@ngrx/store           : 19.0.0
@ngrx/store-devtools  : 19.0.0
---------------------------------------
Cache Usage: 11.28 MB / 22.83 GB

Failure Logs

NX   Cannot read properties of undefined (reading 'data')

HookWebpackError: Cannot read properties of undefined (reading 'data')
    at makeWebpackError (/path/to/project/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /path/to/project/node_modules/webpack/lib/Compilation.js:3217:12
    at eval (eval at create (/path/to/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at fn (/path/to/project/node_modules/webpack/lib/Compilation.js:499:17)
    at _next0 (eval at create (/path/to/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/path/to/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/path/to/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/path/to/project/node_modules/tapable/lib/Hook.js:18:14)
    at /path/to/project/node_modules/webpack/lib/Compilation.js:534:46
    at /path/to/project/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9
-- inner error --
TypeError: Cannot read properties of undefined (reading 'data')
    at /path/to/project/node_modules/nx/src/plugins/js/package-json/create-package-json.js:165:55
    at Array.forEach (<anonymous>)
    at findProjectsNpmDependencies (/path/to/project/node_modules/nx/src/plugins/js/package-json/create-package-json.js:163:33)
    at createPackageJson (/path/to/project/node_modules/nx/src/plugins/js/package-json/create-package-json.js:25:21)
    at /path/to/project/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:30:64
    at fn (/path/to/project/node_modules/webpack/lib/Compilation.js:497:10)
    at _next0 (eval at create (/path/to/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/path/to/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/path/to/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/path/to/project/node_modules/tapable/lib/Hook.js:18:14)
    at /path/to/project/node_modules/webpack/lib/Compilation.js:534:46
    at /path/to/project/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: bundlers Issues related to webpack, rollup label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

No branches or pull requests

3 participants