King Rayhan
King Rayhan

Reputation: 2479

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

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'

enter image description here

Note: I installed all packages using pnpm

Upvotes: 6

Views: 2431

Answers (1)

Jay McDoniel
Jay McDoniel

Reputation: 70590

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

Upvotes: 7

Related Questions