背景

yarn set version stable

将 Yarn 从 v1 升级到 v3 后,使用 Yarn 3 执行 yarn install 安装项目依赖后,没有 node_modules 文件夹

原因

执行 yarn install 安装依赖后提示成功,也没有报错,于是去文档 FAQ 的部分看能不能找到有用的信息,尝试搜索一下 module,果然找到了相关的信息:

Some tools (mostly React Native and Flow) will require downgrading to the node_modules install strategy by setting the nodeLinker setting to node-modules. TypeScript doesn’t have this problem.

定位到 nodeLinker 这个配置,于是查了一下这个配置详细的说明:

Defines what linker should be used for installing Node packages (useful to enable the node-modules plugin), one of: pnp, pnpm and node-modules.

nodeLinker: "pnp"

这个配置目前的默认值是 pnp,取值范围是:[ pnp | pnpm | node-modules ]

pnp 是类似 pnpm 的方式,内置在 Yarn v3 中,但当前报错的项目不支持,所以需要降级。

解决方案

nodeLinker 降级为 node-modules

yarn config set nodeLinker node-modules

然后重新安装依赖:

yarn install

备注:随时间推移相关内容和链接可能过时,可以查看官方文档,以实际内容为准。

参考链接

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐