Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Yarn's `.pnp.js` file?

Using Yarn 2 or later, the default installation method creates a .pnp.js file (Plug'n'Play) instead of a node_modules directory.

How do I use this file to run my Node application?

like image 411
Demurgos Avatar asked Nov 26 '25 04:11

Demurgos


1 Answers

To run a Node application with Yarn's Plug'n'Play you must preload the .pnp.js file using the --require flag.

node --require ./.pnp.js foo.js

Note: Make sure that the --require path starts with ./ or ../.

To start an ESM application, you also need to use the --loader flag (both flags are needed).

node --require ./.pnp.cjs --loader ./.pnp.loader.mjs foo.mjs
like image 199
Demurgos Avatar answered Nov 27 '25 19:11

Demurgos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!