gpt4 book ai didi

javascript - 导入别名 'theme'的循环定义

转载 作者:行者123 更新时间:2023-12-04 11:33:20 32 4
gpt4 key购买 nike

我正在尝试扩展第三方私有(private) npm 模块的主题。项目编译成功,但我不断收到 typescript 错误 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 导入引用循环依赖,我不确定这到底意味着什么,并且在研究时没有找到任何明确的引用。
这些是我的 typescript 设置
        "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。如果两个模块执行类似的行为,它们也可以组合成一个模块。

关于javascript - 导入别名 'theme'的循环定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68176334/

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