问题
Yarn berry (v2) got rid of node_modules (which I really love) by introducing pnp. However, scripts executed by node directly don't understand pnp modules, so you have to use yarn to run such a script.
Is there some way (e.g. a require script like ts-node provides) so that I can still use node to launch my script that requires pnp modules?
Background is that I want to configure the Mocha Sidebar extension for VS Code to support pnp. I can add configure node options there and specify files that are required automatically.
回答1:
That's the (undocumented) solution:
require(".pnp.js").setup();
来源:https://stackoverflow.com/questions/61475926/yarn-berry-run-a-node-script-directly