javascript - 导入别名“主题”的循环定义
问题描述
我正在尝试扩展第三方私有 npm 模块的主题。项目编译成功,但我不断收到打字稿错误Circular definition of import alias 'externalTheme'
下面是我如何扩展主题。这完美地结合了我的主题和外部主题
import { externalTheme, ExternalThemeInterface } from 'external-npm-repo...'
import { colors, ColorsTypes } from './colors'
export const MyTheme: MyThemeInterface = {
...theme,
colors,
}
export interface MyThemeInterface extends ExternalThemeInterface {
colors: ColorsTypes
}
我得到的错误是使用 externalTheme 导入引用循环依赖,我不确定这到底意味着什么,并且在研究时没有找到任何明确的参考。
这些是我的打字稿设置
"allowJs": true,
"alwaysStrict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "preserve",
"lib": ["dom", "es2017"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
解决方案
当两个或多个模块相互引用时,就会发生循环依赖(也称为循环依赖)。
这可以是直接引用(A -> B -> A):
或间接引用(A -> B -> C -> A):
。
创建一个文件webpack.config.js
并尝试将其添加circular-dependency-plugin
到您的 webpack 配置https://www.npmjs.com/package/circular-dependency-plugin。这应该在您的代码中显示循环依赖。
您的代码看起来像这种类型(A -> B -> A):
因此,对于更简单的模式,例如 A -> B -> A,refactoring
可能是必要的。也许 B 中的模块可以移动到 A。或者,可以将必要的代码提取到 A 和 B 都引用的 C。如果两个模块执行类似的行为,它们也可以组合成一个模块。
推荐阅读
- webpack - 无法正确设置下一个配置故事书以从 url 获取图像
- ruby-on-rails - 如何获得所有具有共同状态的订单?
- php - Laravel 测试积极缓存 json 请求
- .net - 使用 Vue 3 前端组件处理来自 .NET 后端的 JSON 对象
- javascript - 如何更改说命令以要求通道 ID 并将消息发送到那里而不是发送命令的位置?
- python - 拥抱脸管道:bert NER 任务抛出 RuntimeError:张量 a (921) 的大小必须与非单维 1 的张量 b (512) 的大小匹配
- python - TypeError:melt() 接受 1 个位置参数,但给出了 2 个
- c++ - 存储嵌套结构并避免内存泄漏
- c++ - C++ 入门第 5 版:operator new 和 operator delete 重载
- php - 用php格式化数字