nx
nx copied to clipboard
Build error: Cannot read properties of undefined (reading 'map')
Current Behavior
Since migrated to the latest version ^14.7.5
, I can't build a Node project anymore.
Expected Behavior
The Node project should build with a custom webpack config.
Steps to Reproduce
-
Create a new Node Webpack project
-
Use the following build config
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/graphql/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/graphql",
"main": "apps/graphql/src/main.ts",
"tsConfig": "apps/graphql/tsconfig.app.json",
"webpackConfig": "apps/graphql/webpack.config.js",
"generatePackageJson": true
},
"configurations": {
"production": {
"optimization": true,
"inspect": false
}
}
},
}
}
- Create a custom webpack config
const { merge } = require('webpack-merge')
const SentryPlugin = require('@sentry/webpack-plugin')
module.exports = (config) => {
if (config.mode === 'production') {
return merge(config, {
plugins: [
new SentryPlugin({ /* all the configs */ })
],
})
} else {
return config
}
}
- Run
nx run graphql:build:production --verbose
Failure Logs
$ nx run graphql:build:production
NX Cannot read properties of undefined (reading 'map')
TypeError: Cannot read properties of undefined (reading 'map')
at normalizeExtraEntryPoints (/Users/xyz/project-x/node_modules/@nrwl/webpack/src/utils/webpack/normalize-entry.js:8:29)
at getCommonConfig (/Users/xyz/project-x/node_modules/@nrwl/webpack/src/utils/webpack/partials/common.js:73:87)
at getCommonPartial (/Users/xyz/project-x/node_modules/@nrwl/webpack/src/executors/webpack/lib/get-webpack-config.js:74:55)
at getWebpackConfig (/Users/xyz/project-x/node_modules/@nrwl/webpack/src/executors/webpack/lib/get-webpack-config.js:57:9)
at /Users/xyz/project-x/node_modules/@nrwl/webpack/src/executors/webpack/webpack.impl.js:44:55
at Generator.next (<anonymous>)
at /Users/xyz/project-x/node_modules/tslib/tslib.js:118:75
at new Promise (<anonymous>)
at Object.__awaiter (/Users/xyz/project-x/node_modules/tslib/tslib.js:114:16)
at getWebpackConfigs (/Users/xyz/project-x/node_modules/@nrwl/webpack/src/executors/webpack/webpack.impl.js:22:20)
Environment
NX Report complete - copy this into the issue template
Node : 16.15.1
OS : darwin arm64
npm : 8.11.0
nx : 14.7.8
@nrwl/angular : Not Found
@nrwl/cypress : 14.7.8
@nrwl/detox : Not Found
@nrwl/devkit : 14.7.8
@nrwl/eslint-plugin-nx : 14.7.8
@nrwl/expo : Not Found
@nrwl/express : 14.7.8
@nrwl/jest : 14.7.8
@nrwl/js : 14.7.8
@nrwl/linter : 14.7.8
@nrwl/nest : Not Found
@nrwl/next : 14.7.8
@nrwl/node : 14.7.8
@nrwl/nx-cloud : 14.6.2
@nrwl/nx-plugin : Not Found
@nrwl/react : 14.7.8
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.7.8
@nrwl/web : 14.7.8
@nrwl/workspace : 14.7.8
typescript : 4.8.3
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
I have same issue
Same here
+1 it starts from @nrwl/node : 14.7.6
onwards
> $ node --version
v16.17.0
> $ arch
aarch64
> $ uname
Linux
> $ npm --version
8.15.0
There was migration script to update executors and options.
Could it be that you have updated nrwl modules without running nx migrate latest
& nx migrate --run-migrations=migrations.json
?
The change should have looked like something like this:
I just went back to the migration commit and there were no changes done on the project.json
file of this app.
There were changes on all other apps project.json
with the following change:
transform: {
- '^.+\\.[tj]sx?$': 'babel-jest',
+ '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }],
},
In the package.json
I only had changes on @nrwl/*
packages from version 14.3.3
to 14.7.5
.
I applay these changes you're showing on this screenshot, and I had to install @nrwl/webpack
manually but then it throws other erros like:
ERROR in ../../node_modules/express/lib/application.js 30:14-37
Module not found: Error: Can't resolve 'path' in '/Users/xyz/project-x/node_modules/express/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
I found a solution with the help of @minijus comment.
- Make sure you have installed
14.7.8
of all@nrwl/*
packages and not14.7.5
. - Change
build
targetexecutor
from@nrwl/node:webpack
to@nrwl/webpack:webpack
and add the following two options:"target": "node"
and"compiler": "tsc"
. - Change the
serve
targetexecutor
from@nrwl/node:node
to@nrwl/js:node"
Your project.json
targets
should look like this:
"build": {
"executor": "@nrwl/webpack:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/graphql",
"main": "apps/graphql/src/main.ts",
"tsConfig": "apps/graphql/tsconfig.app.json",
"webpackConfig": "apps/graphql/webpack.config.js",
"generatePackageJson": true
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false
}
}
},
"serve": {
"executor": "@nrwl/js:node",
"options": {
"buildTarget": "graphql:build"
},
"configurations": {
"production": {
"buildTarget": "graphql:build:production"
}
}
},
Eu tenho o mesmo problema
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.