英文:
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启动项目,但是遇到了以下错误:
注:我使用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'
Note: I installed all packages using pnpm
答案1
得分: 6
你需要确保 @nestjs/common、@nestjs/core、@nestjs/microservice 和 @nestjs/platform-express 全部 使用完全相同的版本。最简单的方法是执行 rm -rf node_modules 和 rm 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论