Search code examples
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

> [email protected] 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:

  • Windows 10
  • Node.js Version: v20.9.0
  • NPM Version: 10.1.0

Nest CLI Information:

  • Nest CLI Version: 10.2.0

Nest Platform Information:

  • platform-express version: 10.2.7
  • schematics version: 10.0.2
  • testing version: 10.2.7
  • common version: 10.2.7
  • core version: 10.2.7
  • cli version: 10.2.0

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/[email protected]. You can downgrade to @nestjs/[email protected] until it is fixed.