nx: [Nest] Nest app build failure with generatePackageJson=true - Nx 18
Current Behavior
Nest app build fails with generatePackageJson=true option
Expected Behavior
Nest app should build without error and generate the package.json file
GitHub Repo
No response
Steps to Reproduce
- Create a new workspace with nx 18
- Install @nx/nest plugin
- Create a nest app
- Update webpack.config.js to include
genetarePackageJson: true - Run build command to build your app
Nx Report
> NX Report complete - copy this into the issue template
Node : 20.11.0
OS : darwin-x64
npm : 10.4.0
nx (global) : 18.0.2
nx : 18.0.2
@nx/js : 18.0.2
@nx/jest : 18.0.2
@nx/linter : 18.0.2
@nx/eslint : 18.0.2
@nx/workspace : 18.0.2
@nx/devkit : 18.0.2
@nx/eslint-plugin : 18.0.2
@nx/nest : 18.0.2
@nx/node : 18.0.2
@nrwl/tao : 18.0.2
@nx/web : 18.0.2
@nx/webpack : 18.0.2
typescript : 5.3.3
---------------------------------------
Community plugins:
@nx-tools/nx-container : 5.2.0
### Failure Logs
```shell
sandbox on main [!+?] via v20.11.0 took 4s
❯ nx run api:build --skip-nx-cache
> NX --skip-nx-cache disables the connection to Nx Cloud for the current run.
The remote cache will not be read from or written to during this run.
> nx run api:build
[webpack-cli] HookWebpackError: ENOENT: no such file or directory, open 'package-lock.json'
at makeWebpackError (/Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/HookWebpackError.js:48:9)
at /Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/Compilation.js:3075:12
at eval (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
at fn (/Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/Compilation.js:481:17)
at _next0 (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
at eval (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
at Hook.eval [as callAsync] (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/Hook.js:18:14)
at /Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/Compilation.js:516:46
at /Users/gperdomor/Downloads/sandbox/node_modules/copy-webpack-plugin/dist/index.js:909:9
-- inner error --
Error: ENOENT: no such file or directory, open 'package-lock.json'
at readFileSync (node:fs:453:20)
at createLockFile (/Users/gperdomor/Downloads/sandbox/node_modules/nx/src/plugins/js/lock-file/lock-file.js:122:43)
at /Users/gperdomor/Downloads/sandbox/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:39:138
at fn (/Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/Compilation.js:479:10)
at _next0 (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
at eval (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
at Hook.eval [as callAsync] (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/Hook.js:18:14)
at /Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/Compilation.js:516:46
at /Users/gperdomor/Downloads/sandbox/node_modules/copy-webpack-plugin/dist/index.js:909:9
caused by plugins in Compilation.hooks.processAssets
Error: ENOENT: no such file or directory, open 'package-lock.json'
at readFileSync (node:fs:453:20)
at createLockFile (/Users/gperdomor/Downloads/sandbox/node_modules/nx/src/plugins/js/lock-file/lock-file.js:122:43)
at /Users/gperdomor/Downloads/sandbox/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:39:138
at fn (/Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/Compilation.js:479:10)
at _next0 (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
at eval (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
at Hook.eval [as callAsync] (eval at create (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/gperdomor/Downloads/sandbox/node_modules/tapable/lib/Hook.js:18:14)
at /Users/gperdomor/Downloads/sandbox/node_modules/webpack/lib/Compilation.js:516:46
at /Users/gperdomor/Downloads/sandbox/node_modules/copy-webpack-plugin/dist/index.js:909:9
Warning: run-commands command "webpack-cli build --node-env=production" exited with non-zero status code
———————————————————————————————————————————————————————————————————————————————————————————————————————————————
### Package Manager Version
npm 10.4.0
### Operating System
- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
### Additional Information
_No response_
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Reactions: 9
- Comments: 27 (7 by maintainers)
@bddy i changed it a bit to be more safer and include all package locks, also it will always copy to the directory of the targets’ project:
Our temp solution until a fix is available:
@ericbf i thought about
dependsOninside thebuildtarget as well but then figured i only really wanted to sync afternpm i. Anyways, with caching and everything generic, that’s an awesome solution we hopefully won’t need anymore with the next update 😄use the project-specific webpack.config.js
fixed manually editing the file
node_modules\nx\src\plugins\js\lock-file\lock-file.jsedited the row 122:const content = (0, fs_1.readFileSync)(getLockFileName(packageManager), 'utf8');toconst content = (0, fs_1.readFileSync)(path_1.join(workspace_root_1.workspaceRoot, getLockFileName(packageManager)), 'utf8');I’m unable to find the actual code in the repository, sorry.
EDIT: found the code that maybe needs to be fixed
@bddy and @alex-mehdi-dev to take it a step even further, enabling cache and allowing it to run before build automatically (only if needed), you can add the cache options and make it a dependency of build, something like. No need to configure any npm script this way:
Additionally I added this line to my
.gitignore:I try it and I still got the problem. In practice it is not that important if I can manage to build production images. I don’t need a lot of speed as it is for development when building them. I will investigate this problem later. I will write here a message if I found something. Thanks for your help !
You can use swc as a compiler with webpack as bunder: https://nx.dev/nx-api/webpack/executors/webpack#compiler
Same here but for ‘pnpm-lock.yaml’.