#Error: Cannot find module '@nestjs/common'

28 messages · Page 1 of 1 (latest)

lilac karma
#

Hello guys, @plucky wadi/common does exist in node_modules, but i am still getting this error

11:36:15 AM] Starting compilation in watch mode...

[11:36:17 AM] Found 0 errors. Watching for file changes.

Error: Cannot find module '@plucky wadi/common'
Require stack:
/Users/sugarDaddy/node_modules/@nestjs/config/dist/conditional.module.js
/Users/sugarDaddy/node_modules/@nestjs/config/dist/index.js
/Users/sugarDaddy/node_modules/@nestjs/config/index.js
/Users/sugarDaddy/Desktop/code/prod/sugar/sugar-backend/dist/app.module.js
/Users/sugarDaddy/Desktop/code/prod/sugar/sugar-backend/dist/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at Function.Module._load (node:internal/modules/cjs/loader:985:27)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/Users/sugarDaddy/node_modules/@nestjs/config/dist/conditional.module.js:4:18)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)

flint thunderBOT
#

Suggestion for @lilac karma:
Please format your question or answer with Markdown formatting.
It leads to better readability and an easier time to spot problems.
For code blocks, you can wrap your block with three back ticks before and after the block, and after the first three back ticks you can add a language (like ts) to add syntax highlighting.
e.g.

```ts
@Injectable()
export class MySuperAwesomeService {
constructor(@Inject('InjectionToken') private readonly dep: SomeDependency) {}

getRandomNumber(): number {
return Math.round(Math.random() * 1000);
}
}
```

Becomes :point_down:

@Injectable()
export class MySuperAwesomeService {
  constructor(@Inject('InjectionToken') private readonly dep: SomeDependency) {}

  getRandomNumber(): number {
    return Math.round(Math.random() * 1000);
  }
}
primal turret
#

show us your package.json file

lilac karma
primal turret
#

well, the @nestjs/* packages are locked to the same major version, which is a good sign.
can you remove the node_modules directory and install the packages again? you might have a broken package-lock.json file.

lilac karma
#

hello @primal turret yes I have done that, I deleted node_modules, I am using pnpm so I deleted pnpm -lock.yaml file as well,
I have reinstalled npm, pnpm, nestjs@cli
restarted my machine
but error persists

flint thunderBOT
#

Please run the command npx -y @nestjs/cli info and paste the output in a code block. This will help us determine if there is a version issue in your packages and which version of nest we are triaging.

lilac karma
lilac karma
#

I tested it running on another machine as well, and I am getting the same errror

lilac karma
#

I created another project to test things out, and I am getting the same error

mental ledge
#

please run pnpm nest info

#

also run pnpm ls @nestjs/common

lilac karma
#

pnpm nest info

 _   _             _      ___  _____  _____  _     _____
| \ | |           | |    |_  |/  ___|/  __ \| |   |_   _|
|  \| |  ___  ___ | |_     | |\ `--. | /  \/| |     | |
| . ` | / _ \/ __|| __|    | | `--. \| |    | |     | |
| |\  ||  __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/  \____/\_____/\___/


[System Information]
OS Version     : macOS 23.1.0
NodeJS Version : v21.6.1
PNPM Version    : 8.13.1 

[Nest CLI]
Nest CLI Version : 10.3.2 

[Nest Platform Information]
platform-express version : 10.3.2
cache-manager version    : 2.2.1
mapped-types version     : 2.0.5
schematics version       : 10.1.1
mongoose version         : 10.0.4
passport version         : 10.0.3
testing version          : 10.3.2
common version           : 10.3.2
core version             : 10.3.2
jwt version              : 10.2.0
cli version              : 10.3.2

pnpm ls @plucky wadi/common

Legend: production dependency, optional only, dev only

atman-backend@0.0.1 /Users/sugarDaddy/Desktop/code/prod/sugar/sugar-backend

dependencies:
@nestjs/common 10.3.2
mental ledge
#

looks good

lilac karma
#

yes, i don't understand why it's happening ?

mental ledge
mental ledge
lilac karma
#

alright thanks @mental ledge
Here's the test project I created, and I keep encountering the same error.

mental ledge
#

and how can we reproduce it here?

lilac karma
#

well, initially I was using pnpm then I thought issue might be from there, so I switched to npm.
for me it's npm install and npm run start:dev

mental ledge
#

using NPM went fine here (after installing a missing dep @nestjs/config)
I don't have PNPM

#

so there might be something wrong in your machine, I guess

#

I'm using linux

lilac karma
#

I tested it on another windows machine and I got the same error, but yes it might be from my machine, I will try again

mental ledge
#

pretty weird

lilac karma
#

one more thing i noticed is, when i run the project empty, without making any changes then it works fine, but the moment i add confingModule or any other package, like winston, mongoose or anything, it gives the same error "@nest/common does not exist in node_modules" it's like it's not able to read node_modules

  ConfigModule.forRoot({
      isGlobal: true,
    }),
lilac karma
#

I did factory reset of my mac to fix the issue, and now it's resolved