nestjs / nest-cli

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

Cannot find module 'dist/main' after upgrading to 10.1.12 #2247

Closed michael-land closed 1 year ago

michael-land commented 1 year ago

Is there an existing issue for this?

Current behavior

❯ pnpm dev

> @app/scheduler@1.1.0 dev /Users/.../apps/app-scheduler
> nest start --watch

>  SWC  Running...
Successfully compiled: 3 files with swc (6.47ms)

 Error  Cannot find module 'dist/main'
Require stack:
- /Users/.../node_modules/.pnpm/@nestjs+cli@10.1.12_@swc+cli@0.1.62_@swc+core@1.3.78/node_modules/@nestjs/cli/actions/start.action.js
- /Users/.../node_modules/.pnpm/@nestjs+cli@10.1.12_@swc+cli@0.1.62_@swc+core@1.3.78/node_modules/@nestjs/cli/actions/index.js
- /Users/.../node_modules/.pnpm/@nestjs+cli@10.1.12_@swc+cli@0.1.62_@swc+core@1.3.78/node_modules/@nestjs/cli/commands/command.loader.js
- /Users/.../node_modules/.pnpm/@nestjs+cli@10.1.12_@swc+cli@0.1.62_@swc+core@1.3.78/node_modules/@nestjs/cli/commands/index.js
- /Users/.../node_modules/.pnpm/@nestjs+cli@10.1.12_@swc+cli@0.1.62_@swc+core@1.3.78/node_modules/@nestjs/cli/bin/nest.js

Watching for file changes.

Minimum reproduction code

Steps to reproduce

No response

Expected behavior

no error

Package version

10.1.12

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 1 year ago

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

michael-land commented 1 year ago

should be related to #2245

michael-land commented 1 year ago

@kamilmysliwiec

The problem persists even after upgrading to version 10.1.13. in this pr #2228, it resolve absolute path. The problem revolves around the inability of the nodejs require.resolve function to function correctly with absolute paths.

https://github.com/nestjs/nest-cli/blob/master/lib/configuration/defaults.ts#L29C14-L29C27.

By default, the "outdir" is set to "dist" but I recommend changing it to "./dist"

To address this problem, a workaround involves adding the following line to your tsconfig.json file to override the default value:

{
    "outDir": "./dist",
}

to reproduce, see https://codesandbox.io/p/sandbox/github/nestjs/typescript-starter/tree/master?file=%2Fpackage.json%3A29%2C26

CleanShot 2023-08-22 at 22 03 20@2x
kamilmysliwiec commented 1 year ago

Should we revert https://github.com/nestjs/nest-cli/pull/2228 for the time being then?

zhangyuang commented 1 year ago

The problem remains

kamilmysliwiec commented 1 year ago

Could you test with 10.1.14?

michael-land commented 1 year ago

Could you test with 10.1.14?

10.1.14 is functional as expected