nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.97k stars 394 forks source link

Nest start failling when path has spaces #2358

Closed mateussaggin closed 1 year ago

mateussaggin commented 1 year ago

Is there an existing issue for this?

Current behavior

Running nest start on a folder that the full path has a space throws module not found error. You can use the starter to test that behavior.

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

Error: Cannot find module '/Users/My'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at internalRequire (node:internal/modules/cjs/loader:175:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1582:5)
    at loadPreloadModules (node:internal/process/pre_execution:731:5)
    at setupUserModules (node:internal/process/pre_execution:172:3)
    at prepareExecution (node:internal/process/pre_execution:132:5)
    at prepareMainThreadExecution (node:internal/process/pre_execution:55:10)
    at node:internal/main/run_main_module:11:19 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}
image

Minimum reproduction code

https://github.com/nestjs/typescript-starter

Steps to reproduce

  1. Create a folder that has an space in any location. E.g.: mkdir /Users/My\ Test
  2. Inside the folder run nest new test
  3. nest start

Expected behavior

We should be able to run projects that the full path has spaces.

Package version

10.2.0

NestJS version

10.2.7

Node.js version

20.9.0

In which operating systems have you tested?

Other

No response

vqhdev commented 1 year ago

https://stackoverflow.com/questions/77358249/error-cannot-find-module-when-path-contains-spaces-on-windows-in-node-js I get the same error on Windows

kamilmysliwiec commented 1 year ago

Would you like to create a PR for this issue?

LeoAso commented 1 year ago

I'm not familiar enough with the NestJS source to be sure that this is the cause, but when I looked for all the changes between 10.1.18 and 10.2.0, I found this:

const sourceMapsRegisterPath = this.getSourceMapSupportPkg();
if (sourceMapsRegisterPath !== undefined) {
  processArgs.unshift(`-r ${sourceMapsRegisterPath}`);
}

It seems to me that the lack of quotes around sourceMapsRegisterPath is the issue here.

kamilmysliwiec commented 1 year ago

Let's track this here https://github.com/nestjs/nest-cli/pull/2359