nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.9k stars 7.55k forks source link

Nestjs's modules could not be resolved in typescript resolutionmode of `classic` #341

Closed chigix closed 6 years ago

chigix commented 6 years ago

I'm submitting a...


[ ] Regression 
[x] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Because I need to use path mapping support for es6 module, moduleResolution in tsconfig.json is set as classic. Then errors about unable resolving modules appear in building task:

> tsc.cmd -p "c:\Users\Project\tsconfig.json" <

src/Authentication/auth.module.ts(1,49): error TS2307: Cannot find module '@nestjs/common/interfaces'.
src/Authentication/auth.module.ts(2,24): error TS2307: Cannot find module '@nestjs/common'.
src/Authentication/auth.service.ts(2,27): error TS2307: Cannot find module '@nestjs/common'.
src/Authentication/jwt.strategy.ts(3,27): error TS2307: Cannot find module '@nestjs/common'.
src/application/app.module.ts(1,24): error TS2307: Cannot find module '@nestjs/common'.
src/domain/model/user.entity.ts(1,56): error TS2307: Cannot find module 'typeorm'.
src/domain/model/user.service.ts(2,35): error TS2307: Cannot find module '@nestjs/common'.
src/main.ts(1,29): error TS2307: Cannot find module '@nestjs/core'.
The terminal process terminated with exit code: 1

Expected behavior

No module resolution error when typescript module resolution strategy set as classic.

Minimal reproduction of the problem with instructions

Directly make one modification in official starter project: https://github.com/nestjs/typescript-starter

What is the motivation / use case for changing the behavior?

Although I could write whole path to export file under @nestjs in node_modules folder, but it is not convenient and not friendly for IDE (Which I am using is VSCode).

Environment


Nest version: 4.5.6

For Tooling issues:
- Node version: 8.9.0- Platform:  

Others:

VSCODE: 1.19.1
chanlito commented 6 years ago

@chigix Are you sure u can use moduleResolution "classic" with node.js?

chigix commented 6 years ago

Because I compile to es6 modules, moduleResolution is defaultly set as classic through typescript document. Although there seems no problem to use es6 module on node.js, is it recommended to actually set module resolution as node manually?

chanlito commented 6 years ago

u can't use es6 modules in node.js just yet, so u have to compile your ts code to commonjs.

{
...
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "outDir": "dist",
    "sourceMap": true,
    "target": "es6"
  },
...
}

Remember node.js right now has all es6 features except es6 module.

chigix commented 6 years ago

OK, I got it and thanks for your advice.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.