Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off yarn@2 PnP?

Tags:

yarnpkg

I am using yarn 2.0.0-rc.27 + workspaces + typescript and I want to turn PnP off and use node_modules again. I tried it with following setting in package.json:

  "installConfig": {
    "pnp": false
  },

But yarn uses PnP mode every time. Is there any option to turn it off?

like image 694
user606521 Avatar asked Jan 31 '20 22:01

user606521


People also ask

What is PNP in yarn install mode?

In this install mode (the default starting from Yarn 2.0), Yarn generates a single .pnp.cjs file instead of the usual node_modules folder containing copies of various packages.

What happens when you remove a yarn package?

Note: yarn remove will always update your package.json and yarn.lock. This ensures that different developers on the same project get the same set of dependencies. It is not possible to disable this behavior. Note: yarn remove <package> --<flag> uses the same flag s as yarn install command.

How do I troubleshoot yarn?

In case you find something that does not work, you should consult the Yarn's Troubleshooting section for some tips, then open an issue if things are still problematic. and finally put node_modules behind us once and for all.

What is yarn plug'n'play?

Yarn Plug'n'Play provides semantic errors (explaining you the exact reason why a package isn't reachable from another) and a sensible JS API to solve various shortcomings with require.resolve. These are features that import maps wouldn't solve by themselves.


2 Answers

I ran into a bunch of issues with Yarn 2 as well using same stack. Solution is to create a .yarnrc.yml file with the following line:

nodeLinker: node-modules
like image 73
Runi Avatar answered Jan 28 '23 16:01

Runi


Sometimes it is enough to run yarn unplug [problem package name] to get it working again with pnp mode.

For instance in case of next.js v12 pnp mode started to not work again (it worked with v10/v11) and the solution was to simply yarn unplug next -- it remembers that you did it by adding a new dependenciesMeta entry into the package.json file.

like image 29
Csaba K. Avatar answered Jan 28 '23 17:01

Csaba K.