gpt4 book ai didi

node.js - yarn pnp 回退到默认要求

转载 作者:行者123 更新时间:2023-12-05 05:56:45 25 4
gpt4 key购买 nike

我正在编写一些单元测试来检查 my-module 是否正确加载用户空间模块 external-module:

const myMod = require('my-module')

myMod( { load: 'external-module' } )

现在我遇到了错误:

Your application tried to access transport, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.  Required package: transport Required by: /Users/mspigolon/workspace/pino/test/  Require stack: - /Users/mspigolon/workspace/pino/test/transport.test.js

这是响亮而清晰的,因为测试在运行时在 node_modules 文件夹中创建了依赖关系,并且在安装阶段它没有被 yarn 处理。

  await symlink(
join(__dirname, 'fixtures', 'transport'),
join(__dirname, '..', 'node_modules', 'transport')
)

我找不到告诉 yarn@3.0.1 回退到文件系统的方法。

我读到了 PnPApi但我没有弄清楚如何使用它们来加载在运行时创建的这个依赖项。你可以帮帮我吗?这是正确的选择还是您认为有更好的方法?

我试过 pnpIgnorePatterns选项,但它会忽略整个文件,而不仅仅是一个 require

另一个解决方案是发布 test-transport-module 并在我看来安装它,但我会避免它。

我的 yarnrc 非常简单:

yarnPath: ".yarn/releases/yarn-berry.cjs"
nodeLinker: pnp
pnpMode: loose

你有什么建议吗?

最佳答案

最好的解决方案是在 link: protocol 中安装依赖项

yarn add --dev transport@link:./test/fixtures/transport

关于node.js - yarn pnp 回退到默认要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69010298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com