typescriptnestjsyarn-v3

Cannot find module or its corresponding type declarations in NestJs with Yarn 3


I created a NestJs app like this:
nest new .
The files were generated and run:
yarn
to install all dependecines.
Then run:
yarn start:dev
And here is the error:

src/app.controller.ts:1:33 - error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.

1 import { Controller, Get } from '@nestjs/common';
                                  ~~~~~~~~~~~~~~~~

src/app.module.ts:1:24 - error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.

1 import { Module } from '@nestjs/common';
                         ~~~~~~~~~~~~~~~~

src/app.service.ts:1:28 - error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.

1 import { Injectable } from '@nestjs/common';
                             ~~~~~~~~~~~~~~~~

src/main.ts:1:29 - error TS2307: Cannot find module '@nestjs/core' or its corresponding type declarations.

1 import { NestFactory } from '@nestjs/core';

Yarn version: 3.2.2
Node version: 16.16.0
Nest version: 9.1.2

Any ideas ?


Solution

  • To resolve this issue with VSCode I navigated to the root of my project in the terminal and entered the following two commands:

    yarn add eslint

    yarn dlx @yarnpkg/sdks vscode

    If you are using a different IDE, then check out yarn's documentation for setting up pnp for that IDE at https://yarnpkg.com/getting-started/editor-sdks