nx icon indicating copy to clipboard operation
nx copied to clipboard

Build error: Cannot read properties of undefined (reading 'map')

Open lailo opened this issue 2 years ago • 3 comments

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

  1. Create a new Node Webpack project

  2. 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
        }
      }
    },
  }
}
  1. 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
  }
}

  1. 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:

lailo avatar Sep 21 '22 18:09 lailo

I have same issue

hoangtrucit avatar Sep 21 '22 19:09 hoangtrucit

Same here

vojtesaak avatar Sep 21 '22 21:09 vojtesaak

+1 it starts from @nrwl/node : 14.7.6 onwards

> $ node --version
v16.17.0

> $ arch
aarch64

> $ uname
Linux

> $ npm --version
8.15.0

sescotti avatar Sep 21 '22 21:09 sescotti

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: image

minijus avatar Sep 22 '22 05:09 minijus

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 }

lailo avatar Sep 22 '22 06:09 lailo

I found a solution with the help of @minijus comment.

  1. Make sure you have installed 14.7.8 of all @nrwl/* packages and not 14.7.5.
  2. Change build target executor from @nrwl/node:webpack to @nrwl/webpack:webpack and add the following two options: "target": "node" and "compiler": "tsc".
  3. Change the serve target executor 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"
        }
      }
    },

lailo avatar Sep 22 '22 11:09 lailo

Eu tenho o mesmo problema

ClenildoCardoso avatar Jan 13 '23 22:01 ClenildoCardoso

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.

github-actions[bot] avatar Mar 21 '23 01:03 github-actions[bot]