javascript - Webpack 提供的依赖使我的应用程序陷入循环依赖
问题描述
当我在我的 web 应用程序中包含一些外部库并开始使用 Webpack (5.45.1) 构建它时,出现了那个旧的好错误:Cannot read property <..> of undefined
. 进入杂草,我发现问题是循环依赖。外部库请求 Node.jsutil
一个,随后的依赖关系图如下所示:
./node_modules/util/util.js -> node_modules/console-browserify/index.js -> ./node_modules/assert/build/assert.js -> ./node_modules/assert/../assertion_error.js -> ./node_modules/util/util.js
事实证明,在导出某些内容之前util
请求console-browserify
并assert
需要util
导出内容,因此会出现该错误。
而且,原来的util.js
包根本不依赖console-browserify
,它是通过Webpack通过以下方式注入到那里的:
/* provided dependency */ var console = __webpack_require__(/*! ./node_modules/console-browserify/index.js */ "./node_modules/console-browserify/index.js");
我该如何解决这个问题?为什么 Webpack 会引入这种依赖?
解决方案
推荐阅读
- javascript - javacript 字符串文字意外行为
- python - Django DecimalField 不一致的舍入
- python - 检查迭代期间字典值中是否存在子字符串
- c# - 发布 Nuget 包时有关 PackageReference 版本的最佳实践?
- sql - 在预期条件的上下文中指定的非布尔类型表达式 Near LEFT JOIN USER
- asp.net - 在阿拉伯语 Web 开发中使用 itextsharp 导出 pdf 文件中的 gridview
- sql - MariaDB 设置数据传输大小
- ios - Swift 测试中的 @testable 导入问题
- rjags - 如何在 rjags 中为非负因子载荷指定尖峰和平板先验
- gcc - 如果我使用 AVX 指令编译代码,然后在没有 AVX 扩展的 CPU 上运行代码,会发生什么情况?