nx
nx copied to clipboard
Build fails with @nx/webpack:webpack executor when setting generatePackageJson to true
Current Behavior
An error is raised when trying to build app with @nx/webpack:webpack executor while the generatePackageJson option is set to true
Expected Behavior
Successful build
GitHub Repo
No response
Steps to Reproduce
- Create a workspace
- Generate a nestjs app
- Update build task executor in app
project.json: set build task executor to@nx/webpack:webpackand set options accordingly - Run
nx build <app_name>
Nx Report
NX Report complete - copy this into the issue template
Node : 20.11.1
OS : darwin-x64
pnpm : 8.15.3
nx : 18.0.5
@nx/js : 18.0.5
@nx/jest : 18.0.5
@nx/linter : 18.0.5
@nx/eslint : 18.0.5
@nx/workspace : 18.0.5
@nx/devkit : 18.0.5
@nx/eslint-plugin : 18.0.5
@nx/nest : 18.0.5
@nx/node : 18.0.5
@nx/playwright : 18.0.5
@nx/react : 18.0.5
@nx/remix : 18.0.5
@nrwl/tao : 18.0.5
@nx/vite : 18.0.5
@nx/web : 18.0.5
@nx/webpack : 18.0.5
typescript : 5.3.3
---------------------------------------
Community plugins:
@nx-tools/nx-container : 5.2.0
Failure Logs
NX The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object
Pass --verbose to see the stacktrace.
Package Manager Version
Operating System
- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
// webpack.config.js
const { NxWebpackPlugin } = require('@nx/webpack')
const { join } = require('path')
module.exports = {
output: {
path: join(__dirname, '../../dist/apps/gateway'),
},
plugins: [
new NxWebpackPlugin({
target: 'node',
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
assets: ['./src/assets'],
optimization: false,
outputHashing: 'none',
generatePackageJson: true,
}),
],
}
Target config in project.json
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"webpackConfig": "apps/gateway/webpack.config.js",
"outputPath": "dist/apps/gateway"
}
}
Hi, Any update on this ?
Hello, any update on this, please?
I cannot reproduce this, I am using generate package successfully in my project. Check you guys are setting out path correctly
@dan-cooke can you provide the github project for us to compare? and what do you mean by "setting out path correctly">
@SirPhemmiey i cannot provide the repo as it’s private.
But I had previously experienced this error message because I was not setting the webpack plugins outputPath in my project json
I can give you an example of a working config later
@dan-cooke i would highly appreciate it, thank you.
Hi @dan-cooke , could you provide the configuration example you mentioned in your last comment?
{
"name": "api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/api/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"options": {
"webpackConfig": "apps/api/webpack.config.js",
"outputPath": "dist/apps/api"
}
}
}
const { NxWebpackPlugin } = require('@nx/webpack');
const { join } = require('path');
module.exports = {
output: {
path: join(__dirname, '../../dist/apps/api'),
},
plugins: [
new NxWebpackPlugin({
target: 'node',
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
generatePackageJson: true,
transformers: [
{
name: '@nestjs/swagger/plugin',
options: {
introspectComments: true,
},
},
],
assets: ['./src/assets'],
optimization: false,
outputHashing: 'none',
}),
],
};
Works for me
I can post a min repro someday soon, but have you made sure you are not running with the nx cache? I always run my builds with --skipNxCache because i've found it to be stale most of the time
Edit: Just realised im missing outputPath, I added that in and it still works
Node : 20.9.0
OS : linux-x64
yarn : 1.22.22
nx (global) : 18.0.8
nx : 18.0.6
@nx/js : 18.0.6
@nx/jest : 18.0.6
@nx/linter : 18.0.6
@nx/eslint : 18.0.6
@nx/workspace : 18.0.6
@nx/cypress : 18.0.6
@nx/devkit : 18.0.6
@nx/esbuild : 18.0.6
@nx/eslint-plugin : 18.0.6
@nx/nest : 18.0.6
@nx/node : 18.0.6
@nx/react : 18.0.6
@nrwl/tao : 18.0.6
@nx/vite : 18.0.6
@nx/web : 18.0.6
@nx/webpack : 18.0.6
typescript : 5.3.3
---------------------------------------
Community plugins:
@nx-extend/shadcn-ui : 1.0.0
Hi @dan-cooke, Thanks. Testing it...
I'm not sure if this helps but I ran into this issue with an application that was using TSC that was importing a SWC library with a custom executor I wrote to generate the application's package json since it couldn't use esbuild or webpack.
My executor looked like this
// The call to getHelperDependenciesFromProjectGraph was failing
const helperDependencies = getHelperDependenciesFromProjectGraph(
context.root,
context.projectName!,
context.projectGraph!
);
const packageJson = createPackageJson(context.projectName!, context.projectGraph!, {
target: context.targetName,
root: context.root,
isProduction: true,
helperDependencies: helperDependencies.map((dep) => dep.target),
});
Removing the function call getHelperDependenciesFromProjectGraph and passing in an empty array for helperDependencies alleviated the issue for that application
This issue has been resolved and therefore I'm going to close it.
Thanks everyone for weighing in!
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.