node.jsnpmnestjsnpm-start

Error: Cannot find module when path contains spaces on Windows in Node.js


I'm encountering an issue when trying to run an npm script with a path that contains spaces on Windows. The error I'm getting is as follows:

E:\A B C\ny-project>npm start

> ny-project@0.0.1 start
> nest start

node:internal/modules/cjs/loader:1051
  throw err;
  ^

Error: Cannot find module 'E:\A'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at internalRequire (node:internal/modules/cjs/loader:166:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1420:5)
    at loadPreloadModules (node:internal/process/pre_execution:705:5)
    at setupUserModules (node:internal/process/pre_execution:170:3)
    at prepareExecution (node:internal/process/pre_execution:132:5)
    at prepareMainThreadExecution (node:internal/process/pre_execution:55:3)
    at node:internal/main/run_main_module:10:1 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}

Node.js v20.9.0

However, when I change the path to 'E:\ABC\ny-project', the script runs without any issues.

System Information:

OS Version:

Nest CLI Information:

Nest Platform Information:

I suspect the issue is related to how Node.js handles paths with spaces on Windows. Any insights or suggestions on how to resolve this problem would be greatly appreciated. Thanks.


Solution

  • It's a bug in @nestjs/cli@10.2.0. You can downgrade to @nestjs/cli@10.1.18 until it is fixed.