Search code examples
yarnpkgyarnpkg-v2

yarn berry run how to run installed packages


I see with yarn berry I get the plug'n'play feature instead of node_modules/

I couldn't find anything to suggest it supports running from installed packages.

For example with npm a workflow might be to run the installed version of webpack:

$ npm install --save-dev webpack
$ node node_modules/webpack/bin/webpack ...

A globally installed webpack might not be the same version. Worse yet, during Docker deployment, I get what's installed locally, the only node and npm are available globally. I thought I can do a preinstall script that does npm install -g yarn; yarn set version berry but then I'm not sure how to do webpack, jest, babel, etc, and the thought that I should have to install them all globally during the same preinstall hackaround seems like several steps backwards.

Is there some way to run from locally-installed packages that I'm missing?

I saw this possibly related question - Yarn Berry - Run a Node Script Directly

But the answer there seems a bit off the point - I'm not running any js, I'm trying to type in a package.json script, i.e. something that can run from the shell.


Solution

  • Why not just use yarn run <bin> (or simply yarn <bin>)? If you are in a repository set to use yarn berry, that will run any package bin file.

    yarn node <file> will run any .js file with Plug n' Play set up. No need to install those dependencies globally, except for maybe yarn classic.