4

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.

joshwilsonvu
  • 2,569
  • 9
  • 20

2 Answers2

3

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.

joshwilsonvu
  • 2,569
  • 9
  • 20
0

I was trying to do yarn some-bin and kept getting:

Couldn't find a script named "some-bin".

I eventually figured out it was because the package that provides some-bin is installed inside a workspace and not at the root of my project. So instead I had to run:

yarn workspace my-workspace some-bin

And that worked.

Cam Jackson
  • 11,860
  • 8
  • 45
  • 78