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
67.73k stars 7.63k forks source link

@nestjs/mapped-types is not found after using `nest g resource user` #6642

Closed GregEisenberg closed 3 years ago

GregEisenberg commented 3 years ago

Bug Report

After running nest g resource user to create a new resource module for "user" (with controller, service and entities stubbed) the pre-generated update-user.dto.ts fails to resolve import { PartialType } from '@nestjs/mapped-types';

Current behavior

Assuming npm i -g @nestjs/cli has been run

  1. run nest new test-project to create a test project
  2. run npm install --save @nestjs/typeorm typeorm postgres pg to get TypeOrm and Postgres support in place
  3. run nest g resource user to create a user module
  4. run npm start run to test

(its possible #2 is not a required step of the repro)

Expected behavior

awesomeness

Actual behavior

src/user/dto/update-user.dto.ts:1:29 - error TS2307: Cannot find module '@nestjs/mapped-types' or its corresponding type declarations.

1 import { PartialType } from '@nestjs/mapped-types';
                              ~~~~~~~~~~~~~~~~~~~~~~

Possible Solution

worked around by manually running npm i --save @nestjs/mapped-types which is fine - but no place in the docs does it reference that this package would have to be installed separately - thus I decided I would submit this issue.

Environment


Nest version:
> nest --version
7.5.6

- Platform:   Windows WSL 2 using Ubuntu 20.04.2 LTS

BTW - thanks for the awesome NestJS platform!

jmcdo29 commented 3 years ago

@kamilmysliwiec should we add this as a step to the resource generation (check if @nestjs/mapped-types is installed and install it if not) or just add a note in the docs saying this package should be installed?

GregEisenberg commented 3 years ago

If you are asking me - my opinion is that since the resource generation code inserts import { PartialType } from '@nestjs/mapped-types'; then the resource generation code is responsible to (check if @nestjs/mapped-types is installed and install it if not)

kamilmysliwiec commented 3 years ago

Added in @nestjs/schematics@7.3.0

HolikovOleksandr commented 9 months ago

In my case @nestjs/mapped-types did not install with the command nest g resource user because he needed administrator rights for some reason.

Solution: sudo nest g resource user

Mac/Linux

micalevisk commented 9 months ago

@HolikovOleksandr everything went fine here on Linux:

npm i -g @nestjs/cli@latest # 10.3.0
nest new test-project
cd test-project
npm install --save @nestjs/typeorm typeorm postgres pg
nest g resource user
npm run start

Please provide a minimum reproduction if you want us to take a look on it again.

Also, I'd suggest you to avoid using the globally installed nestjs CLI. Use the one per project instead (via npx nest/yarn nest)