nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.29k stars 2.32k forks source link

Unable to run NestJS app with serve #15168

Closed mikepziegler closed 1 year ago

mikepziegler commented 1 year ago

Current Behavior

I created a new nestjs app named backend without any other library.

When running nx serve backend in terminal, the following output will come:

> nx run backend:serve

 >  NX   Cannot find module 'nx/src/utils/code-frames'

   Require stack:
   - {project root}/node_modules/@nrwl/js/src/utils/typescript/run-type-check.js
   - {project root}/node_modules/@nrwl/js/src/index.js
   - {project root}/node_modules/@nrwl/webpack/src/plugins/generate-package-json-plugin.js
   - {project root}/node_modules/@nrwl/webpack/src/utils/with-nx.js
   - {project root}/node_modules/@nrwl/webpack/src/executors/webpack/lib/get-webpack-config.js
   - {project root}/node_modules/@nrwl/webpack/src/executors/webpack/webpack.impl.js
   - {project root}/node_modules/nx/src/config/workspaces.js
   - {project root}/node_modules/nx/src/command-line/run.js
   - {project root}/node_modules/nx/bin/run-executor.js
   Pass --verbose to see the stacktrace.

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

 >  NX   Running target serve for project backend failed

   Failed tasks:

   - backend:serve

   Hint: run the command with --verbose for more details.

   View structured, searchable error logs at https://nx.app/runs/hjby7jhhN4

Expected Behavior

Nestjs should be running after serve

GitHub Repo

No response

Steps to Reproduce

  1. Create an nx project with npx create-nx-workspace
  2. Select Integrated monorepo
  3. Select package angular
  4. Input some name
  5. App name ui
  6. Run NX build fast > Yes

Documentation from https://nx.dev/packages/nest

  1. Install nestjs package npm install -D @nrwl/nest
  2. Generate nestjs app with nx g @nrwl/nest:app backend
  3. Run app backend with nx serve backend --verbose

Nx Report

Node : 16.14.0
   OS   : darwin x64
   yarn : 1.22.0

   nx : 15.4.0
   @nrwl/angular : 15.4.0
   @nrwl/cypress : 15.4.0
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.4.0
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.4.0
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.7.2
   @nrwl/js : 15.7.2
   @nrwl/linter : 15.4.0
   @nrwl/nest : 15.7.2
   @nrwl/next : Not Found
   @nrwl/node : 15.7.2
   @nrwl/nx-cloud : 15.1.0
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 15.7.2
   @nrwl/workspace : 15.4.0
   @nrwl/vite : Not Found
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

// With verbose

 > nx run backend:serve

 >  NX   Cannot find module 'nx/src/utils/code-frames'

   Require stack:
   - ${projectroot}/node_modules/@nrwl/js/src/utils/typescript/run-type-check.js
   - ${projectroot}/node_modules/@nrwl/js/src/index.js
   - ${projectroot}/node_modules/@nrwl/webpack/src/plugins/generate-package-json-plugin.js
   - ${projectroot}/node_modules/@nrwl/webpack/src/utils/with-nx.js
   - ${projectroot}/node_modules/@nrwl/webpack/src/executors/webpack/lib/get-webpack-config.js
   - ${projectroot}/node_modules/@nrwl/webpack/src/executors/webpack/webpack.impl.js
   - ${projectroot}/node_modules/nx/src/config/workspaces.js
   - ${projectroot}/node_modules/nx/src/command-line/run.js
   - ${projectroot}/node_modules/nx/bin/run-executor.js

Error: Cannot find module 'nx/src/utils/code-frames'
Require stack:
- ${projectroot}/node_modules/@nrwl/js/src/utils/typescript/run-type-check.js
- ${projectroot}/node_modules/@nrwl/js/src/index.js
- ${projectroot}/node_modules/@nrwl/webpack/src/plugins/generate-package-json-plugin.js
- ${projectroot}/node_modules/@nrwl/webpack/src/utils/with-nx.js
- ${projectroot}/node_modules/@nrwl/webpack/src/executors/webpack/lib/get-webpack-config.js
- ${projectroot}/node_modules/@nrwl/webpack/src/executors/webpack/webpack.impl.js
- ${projectroot}/node_modules/nx/src/config/workspaces.js
- ${projectroot}/node_modules/nx/src/command-line/run.js
- ${projectroot}/node_modules/nx/bin/run-executor.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (${projectroot}/node_modules/@nrwl/js/src/utils/typescript/run-type-check.js:8:23)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)

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

 >  NX   Running target serve for project backend failed

   Failed tasks:

   - backend:serve

   Hint: run the command with --verbose for more details.

   View structured, searchable error logs at https://nx.app/runs/rvG7nAH6F4

Additional Information

On Version 15.6.3, running the nestjs app works

mikepziegler commented 1 year ago

Added additional information

AgentEnder commented 1 year ago

Hey @mikepziegler , Some of your @nrwl/* packages don't line up with the version of nx you have installed. Aside from @nrwl/nx-cloud, all packages under the nrwl scope should generally be set up with the same version.

Can you correct this and check that the issue still reproduces? An easy way to fix this would be to run nx migrate {v}, where v is the version of nx you have installed. Alternatively, updating to latest with nx migrate latest would also work.

maphe commented 1 year ago

I'm running into similar issue with the following report

   Node : 18.14.2
   OS   : darwin arm64
   yarn : 1.22.19

   nx                      : 15.7.2
   @nrwl/jest              : 15.7.2
   @nrwl/linter            : 15.7.2
   @nrwl/workspace         : 15.7.2
   @nrwl/angular           : 15.7.2
   @nrwl/cli               : 15.7.2
   @nrwl/cypress           : 15.7.2
   @nrwl/devkit            : 15.7.2
   @nrwl/eslint-plugin-nx  : 15.7.2
   @nrwl/js                : 15.7.2
   @nrwl/nest              : 15.7.2
   @nrwl/node              : 15.7.2
   @nrwl/tao               : 15.7.2
   @nrwl/webpack           : 15.7.2
   @nrwl/nx-cloud          : 15.1.0
   typescript              : 4.8.4
   ---------------------------------------
   Community plugins:
   @auth0/auth0-angular    : 1.10.1
   ng2-charts              : 3.0.9
   @sharethrough/nx-deploy : 2.3.1

NestJS apps failing to run after upgrading to 15.7 with the following error:

 >  NX   Cannot read properties of undefined (reading 'data')

HookWebpackError: Cannot read properties of undefined (reading 'data')
    at makeWebpackError (/Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/Compilation.js:3060:12
    at eval (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:31:1)
    at fn (/Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/Compilation.js:480:17)
    at _next0 (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:28:1)
    at eval (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:45:1)
    at eval (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at /Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/Compilation.js:502:10
    at Hook.eval [as callAsync] (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/Hook.js:18:14)
AgentEnder commented 1 year ago

I'm running into similar issue with the following report

   Node : 18.14.2
   OS   : darwin arm64
   yarn : 1.22.19

   nx                      : 15.7.2
   @nrwl/jest              : 15.7.2
   @nrwl/linter            : 15.7.2
   @nrwl/workspace         : 15.7.2
   @nrwl/angular           : 15.7.2
   @nrwl/cli               : 15.7.2
   @nrwl/cypress           : 15.7.2
   @nrwl/devkit            : 15.7.2
   @nrwl/eslint-plugin-nx  : 15.7.2
   @nrwl/js                : 15.7.2
   @nrwl/nest              : 15.7.2
   @nrwl/node              : 15.7.2
   @nrwl/tao               : 15.7.2
   @nrwl/webpack           : 15.7.2
   @nrwl/nx-cloud          : 15.1.0
   typescript              : 4.8.4
   ---------------------------------------
   Community plugins:
   @auth0/auth0-angular    : 1.10.1
   ng2-charts              : 3.0.9
   @sharethrough/nx-deploy : 2.3.1

NestJS apps failing to run after upgrading to 15.7 with the following error:

 >  NX   Cannot read properties of undefined (reading 'data')

HookWebpackError: Cannot read properties of undefined (reading 'data')
    at makeWebpackError (/Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/Compilation.js:3060:12
    at eval (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:31:1)
    at fn (/Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/Compilation.js:480:17)
    at _next0 (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:28:1)
    at eval (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:45:1)
    at eval (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at /Users/maphe/Workspace/publisher-platform/node_modules/@nrwl/webpack/node_modules/webpack/lib/Compilation.js:502:10
    at Hook.eval [as callAsync] (eval at create (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/maphe/Workspace/publisher-platform/node_modules/tapable/lib/Hook.js:18:14)

This is a different issue, note the stack trace is completely different. Please open a new issue, so it can be triaged separately

maphe commented 1 year ago

Please open a new issue, so it can be triaged separately

Done: #15246

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] commented 1 year ago

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.