nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.75k stars 2.37k forks source link

@nx/webpack:webpack fails when using generatePackageJson option with bun #26640

Open mikeallisonJS opened 5 months ago

mikeallisonJS commented 5 months ago

Current Behavior

When attempting to use bun as package manager, our nestjs and graphql-yoga apps fail to build in @nx/webpack. This seems like the final issue stopping us from migrating to bun as a package manager

Without generatePackageJson it seems to build correctly.

Expected Behavior

Should build to dist with package.json and bun.lockb

GitHub Repo

https://github.com/JesusFilm/core/tree/24-03-MA-feat-bun-package-manager

Steps to Reproduce

  1. nx build api-journeys --verbose

Nx Report

nx (global)    : 19.3.1
nx             : 19.3.1
@nx/js         : 19.3.1
@nx/jest       : 19.3.1
@nx/linter     : 19.3.1
@nx/eslint     : 19.3.1
@nx/workspace  : 19.3.1
@nx/cypress    : 19.3.1
@nx/devkit     : 19.3.1
@nx/express    : 19.3.1
@nx/nest       : 19.3.1
@nx/next       : 19.3.1
@nx/node       : 19.3.1
@nx/react      : 19.3.1
@nx/storybook  : 19.3.1
@nrwl/tao      : 19.3.1
@nx/web        : 19.3.1
@nx/webpack    : 19.3.1
typescript     : 5.2.2

Failure Logs

> nx run api-journeys:build

 NX   Unable to create bun lock files. Run bun install it's just as quick

 NX   argument 'value' must be either string of Buffer

HookWebpackError: argument 'value' must be either string of Buffer
    at makeWebpackError (/workspaces/core/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /workspaces/core/node_modules/webpack/lib/Compilation.js:3181:12
    at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at fn (/workspaces/core/node_modules/webpack/lib/Compilation.js:488:17)
    at _next0 (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/workspaces/core/node_modules/tapable/lib/Hook.js:18:14)
    at /workspaces/core/node_modules/webpack/lib/Compilation.js:523:46
    at /workspaces/core/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9
-- inner error --
TypeError: argument 'value' must be either string of Buffer
    at new RawSource (/workspaces/core/node_modules/webpack-sources/lib/RawSource.js:16:10)
    at /workspaces/core/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:39:82
    at fn (/workspaces/core/node_modules/webpack/lib/Compilation.js:486:10)
    at _next0 (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/workspaces/core/node_modules/tapable/lib/Hook.js:18:14)
    at /workspaces/core/node_modules/webpack/lib/Compilation.js:523:46
    at /workspaces/core/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9

————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Running target build for project api-journeys failed

Package Manager Version

bun 1.1.16

Operating System

Additional Information

Have tried with bun since 1.1.11 and since initial nx bun release

mikeallisonJS commented 4 months ago

new error with Nx 19.4.0



 NX   Unable to create bun lock files. Run bun install it's just as quick

node:internal/process/promises:391
    triggerUncaughtException(err, true /* fromPromise */);
    ^

HookWebpackError: argument 'value' must be either string of Buffer
    at makeWebpackError (/workspaces/core/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /workspaces/core/node_modules/webpack/lib/Compilation.js:3181:12
    at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at fn (/workspaces/core/node_modules/webpack/lib/Compilation.js:488:17)
    at _next0 (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/workspaces/core/node_modules/tapable/lib/Hook.js:18:14)
    at /workspaces/core/node_modules/webpack/lib/Compilation.js:523:46
    at /workspaces/core/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9
-- inner error --
TypeError: argument 'value' must be either string of Buffer
    at new RawSource (/workspaces/core/node_modules/webpack-sources/lib/RawSource.js:16:10)
    at /workspaces/core/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:39:82
    at fn (/workspaces/core/node_modules/webpack/lib/Compilation.js:486:10)
    at _next0 (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/workspaces/core/node_modules/tapable/lib/Hook.js:18:14)
    at /workspaces/core/node_modules/webpack/lib/Compilation.js:523:46
    at /workspaces/core/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9 {
  details: 'caused by plugins in Compilation.hooks.processAssets\n' +
    "TypeError: argument 'value' must be either string of Buffer\n" +
    '    at new RawSource (/workspaces/core/node_modules/webpack-sources/lib/RawSource.js:16:10)\n' +
    '    at /workspaces/core/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:39:82\n' +
    '    at fn (/workspaces/core/node_modules/webpack/lib/Compilation.js:486:10)\n' +
    '    at _next0 (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)\n' +
    '    at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)\n' +
    '    at Hook.eval [as callAsync] (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)\n' +
    '    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/workspaces/core/node_modules/tapable/lib/Hook.js:18:14)\n' +
    '    at /workspaces/core/node_modules/webpack/lib/Compilation.js:523:46\n' +
    '    at /workspaces/core/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9',
  module: undefined,
  loc: undefined,
  hideStack: true,
  chunk: undefined,
  file: undefined,
  hook: 'Compilation.hooks.processAssets',
  error: TypeError: argument 'value' must be either string of Buffer
      at new RawSource (/workspaces/core/node_modules/webpack-sources/lib/RawSource.js:16:10)
      at /workspaces/core/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:39:82
      at fn (/workspaces/core/node_modules/webpack/lib/Compilation.js:486:10)
      at _next0 (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
      at eval (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
      at Hook.eval [as callAsync] (eval at create (/workspaces/core/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/workspaces/core/node_modules/tapable/lib/Hook.js:18:14)
      at /workspaces/core/node_modules/webpack/lib/Compilation.js:523:46
      at /workspaces/core/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9
}

Node.js v20.15.0```
farm16 commented 2 months ago

setting generatePackageJson: false, in webpack config can skip this error, but most likely not a fix

mikeallisonJS commented 2 months ago

setting generatePackageJson: false, in webpack config can skip this error, but most likely not a fix

No, we need individual webpacks generated otherwise our images are extremely bloated.

farm16 commented 2 months ago

@mikeallisonJS not a fix

Yhozen commented 2 months ago

same error in MacOS using node 20, bun as pm and @nx/nest

wiedev-akro commented 2 months ago

same error in Windows using node 20.17.0, bun as pm and @nx/nest

Jordan-Hall commented 2 months ago

Currently bun doesn't support generating lock files which is what generate package json requires. Youl could create a patch that will run bun install in the background

muhamedkarajic commented 2 months ago

Same issue.

Jordan-Hall commented 1 month ago

@jaysoo Should be able to generate lock files soon as a text file bun.lock Should solve quiet a few issues

source: https://x.com/jarredsumner/status/1839056611765268651

guysenpai commented 2 days ago

any update ?

Jordan-Hall commented 2 days ago

@guysenpai Bun not added support for generating lock files yet. Once their added https://github.com/nrwl/nx/pull/28119 should be ok

D-Laur commented 1 hour ago

Faced same issue. I had to switch from bun to npm to make it work.