无法找到模块 ‘@nestjs/core/guards’ 在使用 NestJS 设置微服务时。

huangapple go评论70阅读模式
英文:

Cannot find module '@nestjs/core/guards' when setting up a microservice with NestJS

问题

我正在尝试使用NestJS设置微服务,并在我的package.json文件中添加了以下依赖项:

"dependencies": {
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/microservices": "^9.4.0",
    "@nestjs/platform-express": "^9.0.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.2.0"
}

在运行npm install后,我尝试使用npm run start:dev启动项目,但是遇到了以下错误:

错误:找不到模块'@nestjs/core/guards'
无法找到模块 ‘@nestjs/core/guards’ 在使用 NestJS 设置微服务时。

注:我使用pnpm安装了所有包。

英文:

I'm trying to set up a microservice using NestJS, and I've added the following dependencies in my package.json file:

"dependencies": {
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/microservices": "^9.4.0",
    "@nestjs/platform-express": "^9.0.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.2.0"
}

After running npm install, I tried to start the project using npm run start:dev, but I encountered the following error:

Error: Cannot find module '@nestjs/core/guards'

无法找到模块 ‘@nestjs/core/guards’ 在使用 NestJS 设置微服务时。

Note: I installed all packages using pnpm

答案1

得分: 6

你需要确保 @nestjs/common@nestjs/core@nestjs/microservice@nestjs/platform-express 全部 使用完全相同的版本。最简单的方法是执行 rm -rf node_modulesrm pnpm-lock.yaml,以确保在运行 pnpm i 时它们都以相同的版本安装。否则,您可以在 package.json 中将它们全部设置为相同的版本,然后再次运行 pnpm i 进行重新安装。如果需要帮助选择版本,您还可以尝试 pnpm upgrade --interactive --latest

当您运行 pnpm nest info 时,应该看到上述的包都具有相同的版本。

英文:

You need to make sure @nestjs/common, @nestjs/core, @nestjs/microservice, and @nestjs/platform-express are all on the exact same version. Easiest way to do this is just rm -rf node_modules and rm pnpm-lock.yaml to ensure when you run pnpm i they all come in as the same version. Otherwise, set them all the same in the package.json and pnpm i again to reinstall. You could also try pnpm upgrade --interactive --latest if you want a CLI to help with choosing.

When you run pnpm nest info it should have the aforementioned packages having the same versions

huangapple
  • 本文由 发表于 2023年4月20日 09:51:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059975.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定