nx icon indicating copy to clipboard operation
nx copied to clipboard

NestJs serve failed with Compilation.hooks.processAssets ( Due to generatePackageJson:true )

Open karocksjoelee opened this issue 1 year ago • 2 comments

Current Behavior

Running nest api serve, throwing error

Expected Behavior

Expect to run in serve mode

GitHub Repo

No response

Steps to Reproduce

1.after upgrade to 17.x

Nx Report

Node   : 18.14.2
   OS     : darwin-arm64
   npm    : 9.5.0
   
   nx                 : 17.2.8
   @nx/js             : 17.2.8
   @nx/jest           : 17.2.8
   @nx/linter         : 17.2.8
   @nx/eslint         : 17.2.8
   @nx/workspace      : 17.2.8
   @nx/angular        : 17.2.8
   @nx/cypress        : 17.2.8
   @nx/devkit         : 17.2.8
   @nx/eslint-plugin  : 17.2.8
   @nx/nest           : 17.2.8
   @nx/node           : 17.2.8
   @nrwl/tao          : 17.2.8
   @nx/web            : 17.2.8
   @nx/webpack        : 17.2.8
   typescript         : 5.2.2
   ---------------------------------------
   Community plugins:
   @ionic/angular : 7.5.8
   ng-zorro-antd  : 14.0.0

Failure Logs

Nx no longer reads configuration from workspace.json.
   Run "nx g @nx/workspace:fix-configuration" to split workspace.json into individual project.json files.


> nx run api:serve

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

HookWebpackError: Cannot read properties of undefined (reading 'data')
    at makeWebpackError (/Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:3068:12
    at eval (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at fn (/Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:481:17)
    at _next0 (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/Hook.js:18:14)
    at /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:516:46
    at /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
-- inner error --
TypeError: Cannot read properties of undefined (reading 'data')
    at /Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:124:55
    at Array.forEach (<anonymous>)
    at findProjectsNpmDependencies (/Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:122:33)
    at createPackageJson (/Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:23:21)
    at /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:30:64
    at fn (/Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:479:10)
    at _next0 (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.eval [as callAsync] (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/Hook.js:18:14)
    at /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:516:46
    at /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  details: 'caused by plugins in Compilation.hooks.processAssets\n' +
    "TypeError: Cannot read properties of undefined (reading 'data')\n" +
    '    at /Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:124:55\n' +
    '    at Array.forEach (<anonymous>)\n' +
    '    at findProjectsNpmDependencies (/Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:122:33)\n' +
    '    at createPackageJson (/Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:23:21)\n' +
    '    at /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:30:64\n' +
    '    at fn (/Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:479:10)\n' +
    '    at _next0 (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)\n' +
    '    at eval (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)\n' +
    '    at Hook.eval [as callAsync] (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)\n' +
    '    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/Hook.js:18:14)\n' +
    '    at /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:516:46\n' +
    '    at /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
  module: undefined,
  loc: undefined,
  hideStack: true,
  chunk: undefined,
  file: undefined,
  hook: 'Compilation.hooks.processAssets',
  error: TypeError: Cannot read properties of undefined (reading 'data')
      at /Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:124:55
      at Array.forEach (<anonymous>)
      at findProjectsNpmDependencies (/Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:122:33)
      at createPackageJson (/Users/joeleem1max/Works/nx-posup/node_modules/nx/src/plugins/js/package-json/create-package-json.js:23:21)
      at /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:30:64
      at fn (/Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:479:10)
      at _next0 (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
      at eval (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
      at Hook.eval [as callAsync] (eval at create (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/joeleem1max/Works/nx-posup/node_modules/tapable/lib/Hook.js:18:14)
      at /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compilation.js:516:46
      at /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/node_modules/copy-webpack-plugin/dist/index.js:909:9
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
}

Package Manager Version

yarn 1.22.19

Operating System

  • [X] macOS
  • [ ] Linux
  • [ ] Windows
  • [ ] Other (Please specify)

Additional Information

Project json :

{ "sourceRoot": "apps/api/src", "projectType": "application", "targets": { "build": { "executor": "@nx/webpack:webpack", "outputs": [ "{options.outputPath}" ], "options": { "outputPath": "dist/apps/api", "main": "apps/api/src/main.ts", "tsConfig": "apps/api/tsconfig.app.json", "generatePackageJson": true, "assets": [ "apps/api/src/views/ecpay-order-result.hbs" ], "webpackConfig": "apps/api/webpack.config.js" }, "configurations": { "qa": { "optimization": true, "extractLicenses": true, "inspect": false, "assets": [ "apps/api/src/assets", "apps/api/src/views", { "glob": "api-qa-gae.yaml", "input": "apps/api/src/", "output": "/" }, { "glob": "cron.yaml", "input": "apps/api/src/", "output": "/" }, { "glob": "/*.(conf|csv)", "input": "libs/api/auth/src/casbin/", "output": "libs/api/auth/src/casbin/" }, { "glob": ".env", "input": "env/qa/", "output": "env/" } ], "fileReplacements": [ { "replace": "apps/api/src/environments/environment.ts", "with": "apps/api/src/environments/environment.qa.ts" } ] }, "production": { "optimization": true, "extractLicenses": true, "inspect": false, "assets": [ "apps/api/src/assets", { "glob": "api-prod-gae.yaml", "input": "apps/api/src/", "output": "/" }, { "glob": "cron.yaml", "input": "apps/api/src/", "output": "/" }, { "glob": "/.(conf|csv)", "input": "libs/api/auth/src/casbin/", "output": "libs/api/auth/src/casbin/" }, { "glob": ".env", "input": "env/prod/", "output": "env/" } ], "fileReplacements": [ { "replace": "apps/api/src/environments/environment.ts", "with": "apps/api/src/environments/environment.prod.ts" } ] } } }, "serve": { "executor": "@nx/js:node", "options": { "buildTarget": "api:build" }, "configurations": { "production": { "buildTarget": "api:build:production" } } }, "lint": { "executor": "@nrwl/linter:eslint", "outputs": [ "{options.outputFile}" ], "options": { "lintFilePatterns": [ "apps/api/**/.ts" ] } }, "test": { "executor": "@nrwl/jest:jest", "outputs": [ "coverage/apps/api" ], "options": { "jestConfig": "apps/api/jest.config.ts", "passWithNoTests": true } } }, "tags": [] }

karocksjoelee avatar Jan 09 '24 09:01 karocksjoelee

After removed generatePackageJson:true

ERROR in ./src/main.ts Module build failed (from ../../node_modules/@nx/webpack/src/utils/web-babel-loader.js): Error: Cannot find module '/Users/joeleem1max/Works/nx-posup/apps/api/.babelrc' Require stack:

  • /Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/config/files/configuration.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/config/files/index.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/index.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/babel-loader/lib/index.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/src/utils/web-babel-loader.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/loader-runner/lib/loadLoader.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/loader-runner/lib/LoaderRunner.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/NormalModuleFactory.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/Compiler.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/webpack.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/webpack/lib/index.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/src/executors/webpack/lib/run-webpack.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/@nx/webpack/src/executors/webpack/webpack.impl.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/nx/src/config/schema-utils.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/nx/src/command-line/run/executor-utils.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/nx/src/command-line/run/run.js
  • /Users/joeleem1max/Works/nx-posup/node_modules/nx/bin/run-executor.js at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15) at resolve (node:internal/modules/cjs/helpers:116:19) at loadConfig (/Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/config/files/configuration.js:212:5) at loadConfig.next () at buildRootChain (/Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/config/config-chain.js:65:47) at buildRootChain.next () at loadPrivatePartialConfig (/Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/config/partial.js:72:62) at loadPrivatePartialConfig.next () at loadPartialConfig (/Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/config/partial.js:115:25) at loadPartialConfig.next () at step (/Users/joeleem1max/Works/nx-posup/node_modules/gensync/index.js:261:32) at evaluateAsync (/Users/joeleem1max/Works/nx-posup/node_modules/gensync/index.js:291:5) at /Users/joeleem1max/Works/nx-posup/node_modules/gensync/index.js:93:9 at new Promise () at async (/Users/joeleem1max/Works/nx-posup/node_modules/gensync/index.js:92:14) at stopHiding - secret - don't use this - v1 (/Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:47:12) at Object.loadPartialConfigAsync (/Users/joeleem1max/Works/nx-posup/node_modules/@babel/core/lib/config/index.js:34:85) at Object.loader (/Users/joeleem1max/Works/nx-posup/node_modules/babel-loader/lib/index.js:109:30)

webpack compiled with 1 error (60b2ced7b6ff2a91) Build failed, waiting for changes to restart...

How to Fix this :

Adding "target": "node", and "compiler": "tsc", to project.json.target.build.options

But , still cannot work with generatePackageJson:true

karocksjoelee avatar Jan 09 '24 09:01 karocksjoelee

Im facing a similar issue on nx v 16.7.0 as well

Nx Report

Node   : 18.16.1
OS     : linux-x64
yarn   : 1.22.19

nx              : 16.7.0
@nx/js          : 16.7.3
@nx/jest        : 16.7.3
@nx/linter      : 16.7.3
@nx/workspace   : 16.7.3
@nx/cypress     : 16.7.3
@nx/devkit      : 16.7.3
@nx/nest        : 16.7.3
@nx/next        : 16.7.3
@nx/node        : 17.2.6
@nx/react       : 16.7.3
@nx/storybook   : 16.10.0
@nrwl/tao       : 16.7.0
@nx/web         : 16.7.3
@nx/webpack     : 16.10.0
nx-cloud        : 16.3.0
@nrwl/nx-cloud  : 16.5.2
typescript      : 5.3.3

Serve Output

warning package.json: "dependencies" has dependency "@types/react" with range "^18.2.0" that collides with a dependency in "devDependencies" of the same name with version "18.0.20"
$ /var/www/html/platform-insim/node_modules/.bin/env-cmd -f ./packages/platform/.env.comm nx serve_insim_backend platform --verbose

> nx run platform:serve_insim_backend

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

HookWebpackError: Unknown package manager: [object Object]
    at makeWebpackError (/var/www/html/platform-insim/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:3068:12
    at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:23:1)
    at fn (/var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:481:17)
    at _next0 (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:21:1)
    at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)
    at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at /var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:503:10
    at Hook.eval [as callAsync] (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/html/platform-insim/node_modules/tapable/lib/Hook.js:18:14)
-- inner error --
Error: Unknown package manager: [object Object]
    at getLockFileName (/var/www/html/platform-insim/node_modules/nx/src/plugins/js/lock-file/lock-file.js:115:11)
    at createLockFile (/var/www/html/platform-insim/node_modules/nx/src/plugins/js/lock-file/lock-file.js:128:44)
    at /var/www/html/platform-insim/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:42:138
    at fn (/var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:479:10)
    at _next0 (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:21:1)
    at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)
    at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at /var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:503:10
    at Hook.eval [as callAsync] (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/html/platform-insim/node_modules/tapable/lib/Hook.js:18:14) {
  details: 'caused by plugins in Compilation.hooks.processAssets\n' +
    'Error: Unknown package manager: [object Object]\n' +
    '    at getLockFileName (/var/www/html/platform-insim/node_modules/nx/src/plugins/js/lock-file/lock-file.js:115:11)\n' +
    '    at createLockFile (/var/www/html/platform-insim/node_modules/nx/src/plugins/js/lock-file/lock-file.js:128:44)\n' +
    '    at /var/www/html/platform-insim/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:42:138\n' +
    '    at fn (/var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:479:10)\n' +
    '    at _next0 (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:21:1)\n' +
    '    at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)\n' +
    '    at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)\n' +
    '    at /var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:503:10\n' +
    '    at Hook.eval [as callAsync] (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)\n' +
    '    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/html/platform-insim/node_modules/tapable/lib/Hook.js:18:14)',
  module: undefined,
  loc: undefined,
  hideStack: true,
  chunk: undefined,
  file: undefined,
  hook: 'Compilation.hooks.processAssets',
  error: Error: Unknown package manager: [object Object]
      at getLockFileName (/var/www/html/platform-insim/node_modules/nx/src/plugins/js/lock-file/lock-file.js:115:11)
      at createLockFile (/var/www/html/platform-insim/node_modules/nx/src/plugins/js/lock-file/lock-file.js:128:44)
      at /var/www/html/platform-insim/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:42:138
      at fn (/var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:479:10)
      at _next0 (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:21:1)
      at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)
      at eval (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
      at /var/www/html/platform-insim/node_modules/webpack/lib/Compilation.js:503:10
      at Hook.eval [as callAsync] (eval at create (/var/www/html/platform-insim/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/html/platform-insim/node_modules/tapable/lib/Hook.js:18:14)
}

Node.js v18.16.1

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

 >  NX   Running target serve_insim_backend for project platform failed

   Failed tasks:
   
   - platform:serve_insim_backend
   
   Hint: run the command with --verbose for more details.

error Command failed with exit code 1.

knolskape-arjun avatar Jan 29 '24 09:01 knolskape-arjun

Hi, any update on this yet?

SirPhemmiey avatar Feb 27 '24 16:02 SirPhemmiey

I've fixed this.

Remove "generatePackageJson": true from your project.json if you already have a package.json

SirPhemmiey avatar Feb 27 '24 18:02 SirPhemmiey

In my case this was caused by the new lockfile format introduced by pnpm@9. I rolled the package manager back to pnpm@8 and now it is working again.

agrippa1994 avatar Apr 26 '24 09:04 agrippa1994

can confirm what @agrippa1994 said. rolling back to pnpm v8 resolved this error

yordan-kanchelov avatar Apr 28 '24 16:04 yordan-kanchelov

i also facing this issue, can confirm @agrippa1994 is right.

rizqikazukun avatar Apr 29 '24 07:04 rizqikazukun

same here, error with pnpm 9

Plopix avatar May 14 '24 00:05 Plopix