问题描述
Yarn berry (v2) 通过引入 pnp 摆脱了 node_modules(我非常喜欢).但是node直接执行的脚本不理解pnp模块,所以你必须使用yarn来运行这样的脚本.
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.
是否有某种方法(例如像 ts-node 提供的 require 脚本),以便我仍然可以使用 node 来启动需要 pnp 模块的脚本?
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?
背景是我想为VS Code配置Mocha Sidebar扩展来支持pnp.我可以在那里添加配置节点选项并指定自动需要的文件.
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.
推荐答案
这是(未记录的)解决方案:
That's the (undocumented) solution:
require(".pnp.js").setup();
这篇关于Yarn Berry - 直接运行节点脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!