NodeJS 在nest.js代码库中未找到模块(MODULE_NOT_FOUND)

sg3maiej  于 2022-12-22  发布在  Node.js
关注(0)|答案(3)|浏览(523)

我有一个代码库,它在节点v10.16.3的Windows机器上运行得非常好,但当我尝试在节点v.12.16.3的CentOS Linux机器上安装相同的代码库时,我得到了以下错误。不确定问题可能是什么。

# npm start

> nest start

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

Error: Cannot find module '@angular-devkit/core'
Require stack:
  - /usr/local/lib/node_modules/@nestjs/cli/lib/schematics/schematic.option.js
  - /usr/local/lib/node_modules/@nestjs/cli/lib/schematics/index.js
  - /usr/local/lib/node_modules/@nestjs/cli/actions/generate.action.js
  - /usr/local/lib/node_modules/@nestjs/cli/actions/index.js
  - /usr/local/lib/node_modules/@nestjs/cli/commands/command.loader.js
  - /usr/local/lib/node_modules/@nestjs/cli/commands/index.js
  - /usr/local/lib/node_modules/@nestjs/cli/bin/nest.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> 
(/usr/local/lib/node_modules/@nestjs/cli/lib/schematics/schematic.option.js:3:16)
  at Module._compile (internal/modules/cjs/loader.js:1133:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
  at Module.load (internal/modules/cjs/loader.js:977:32)
  at Function.Module._load (internal/modules/cjs/loader.js:877:14)
  at Module.require (internal/modules/cjs/loader.js:1019:19) {
  code: 'MODULE_NOT_FOUND',
requireStack: [
  '/usr/local/lib/node_modules/@nestjs/cli/lib/schematics/schematic.option.js',
  '/usr/local/lib/node_modules/@nestjs/cli/lib/schematics/index.js',
  '/usr/local/lib/node_modules/@nestjs/cli/actions/generate.action.js',
  '/usr/local/lib/node_modules/@nestjs/cli/actions/index.js',
  '/usr/local/lib/node_modules/@nestjs/cli/commands/command.loader.js',
  '/usr/local/lib/node_modules/@nestjs/cli/commands/index.js',
  '/usr/local/lib/node_modules/@nestjs/cli/bin/nest.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Exit status 1
npm ERR!
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-22T14_14_24_709Z-debug.log
sauutmhj

sauutmhj1#

删除dist文件夹,然后再次运行yarn startnpm startyarn start:devnpm run start:dev以重建dist文件夹。此外,yarn prebuildnpm run prebuild使用rimraf执行相同的操作
如果您更改了名称,而tsc在dist和transpiled .js文件中未更改该名称,则会出现此问题,因此无法找到模块
我认为就我所知,nestjs或tsc这样做是为了使蒸发更快

3htmauhk

3htmauhk2#

没有其他工作对我来说,但以下:

npm install --save-dev webpack

我不完全确定是否有任何负面影响,虽然

oknwwptz

oknwwptz3#

最重要的是,在您启动node js的地方,dist/或/ build文件夹有一个错误的路径,我们导入了该路径,或者NPM需要该路径:npm安装--save-dev webpack和Yarn添加webpack这一个packeg将解决您的问题

相关问题