I'm trying to create a new NestJS project with Yarn as the package manager. After installing NestJS with npm globally (npm install -g @nestjs/cli
), I ran npx nest new [package name] --strict
, then selected Yarn as the package manager in the resulting CLI.
A fresh NestJS project is created. I run yarn
to install the packages, but every module that the files in the generated project try to import throw Cannot find module
e.g.:
Cannot find module '@nestjs/common' or its corresponding type declarations.
It's only when I tried npm install
, which created a node_modules
directory, that the imports work. So it appears that the project is using yarn classic/without Plug 'N Play?
However, when I run yarn -v
in my home directory, I get 3.3.0, so that should mean the global yarn version is 3.3.0 (if there is such thing as a global yarn version)?
yarn -v
inside this new project also gives 3.3.0, and only in another project that I explicitly set to yarn 1x does the command give 1.22.19.
Furthermore, my project does have the .pnp.cjs
and .pnp.loader.mjs
files. So why is it not working without node_modules
?
I even added a .yarnrc.yml
file and added this line inside: nodeLinker: "pnp"
as per this documentation
Not only that, I also tried both recommendations in this stackoverflow thread about having both yarn 1x and 2x projects but it still doesn't work.
How do I get Yarn 3x plug n play to work???