节点如何与 Yarn 即插即用一起使用?

How does node work with Yarn Plug-n-Play?

Yarn 2.0 将 PnP 带入了 table,但我真的不明白如何使用简单的 node 命令 运行 javascript 如果文件在 npm 注册表中具有依赖项。 node 查找 node_modules 文件夹以查找依赖项,但由于 PnP 完全删除了 node_modules 文件夹,我现在是否需要使用 node 以外的命令?或者节点会引入一些新标志来读取 .pnp.js 文件而不是递归地向上查找最近的 node_modules?

来自 Yarn 2 PnP 文档的回答:

Because Node had no concept of packages, it also didn't know whether a file was meant to be accessed (versus being available by the sheer virtue of hoisting). It was entirely possible that the code you wrote worked one day in development but broke later in production because you forgot to list one of your dependencies in your package.json.

对于你的回答你可以运行使用命令node index.js

您需要在 package.json 脚本部分添加一个脚本,例如 "start": "node index.js" 然后 运行 yarn run start

yarn node index.js。请参阅 yarn 2 (berry) 文档。 https://yarnpkg.com/cli/node