node.jsnestjsyarnpkg-v2

starting NestJS with Yarn Berry(not NPM) gets import error


I used to use NestJS with NPM. But now, I wanna try Yarn Berry so I start new NestJS project with yarn. And it's not going well...

Here is my commands and error.

Generate NestJS application

% nest new yarnProject
? Which package manager would you ā¤ļø  to use? yarn

...

šŸš€  Successfully created project yarn-project

Start NestJS application

% yarn install
% yarn start

Error

node:buffer:587
      throw new ERR_INVALID_ARG_TYPE(
            ^

TypeError [ERR_INVALID_ARG_TYPE]: The "list[2]" argument must be an instance of Buffer or Uint8Array. Received type string ('app.controller.d.ts')
    at Function.concat (node:buffer:587:13)
    at node:internal/fs/rimraf:144:32
    at Array.forEach (<anonymous>)
    at node:internal/fs/rimraf:143:5
    at /Users/shin/TodaysProject/yarn-project/.pnp.cjs:12946:13 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v20.17.0

I thought it could be solved by node version. So I changed node version from 20.17.0 to 18.20.4. But it didnt' work and error changed.

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';
                              ~~~~~~~~~~~~~~

Found 4 error(s).

Is there anyone who can solve this problem?


Solution

  • I solved this problem by downgrading Typescript version from 5.x.x to 4.x.x.