为什么我在使用任何 `nx` 命令时都会出错

Why am i getting error on using any `nx` commands

使用的命令:nx

internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module '@nrwl/workspace/src/command-line/supported-nx-commands'
Require stack:
- /Users/shawntony/projects/ktp-web/node_modules/@nrwl/cli/lib/init-local.js
- /Users/shawntony/projects/ktp-web/node_modules/@nrwl/cli/bin/nx.js
- /usr/local/lib/node_modules/@nrwl/cli/lib/init-global.js
- /usr/local/lib/node_modules/@nrwl/cli/bin/nx.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.initLocal (/Users/shawntony/projects/ktp-web/node_modules/@nrwl/cli/lib/init-local.js:12:33)
    at Object.<anonymous> (/Users/shawntony/projects/ktp-web/node_modules/@nrwl/cli/bin/nx.js:12:18)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/shawntony/projects/ktp-web/node_modules/@nrwl/cli/lib/init-local.js',
    '/Users/shawntony/projects/ktp-web/node_modules/@nrwl/cli/bin/nx.js',
    '/usr/local/lib/node_modules/@nrwl/cli/lib/init-global.js',
    '/usr/local/lib/node_modules/@nrwl/cli/bin/nx.js'
  ]
}

我自己刚遇到这个问题。通过删除我的所有 node_modules、验证 npm 缓存、更新我的全局 @nrwl-cli 并重新安装来修复它。简而言之:

  1. rm -rf node_modules
  2. npm cache verify
  3. npm install -g @nrwl/cli
  4. npm install

不确定是什么把戏,但我想它在项目或缓存中的某些@nrwl 模块版本中存在某种不一致。