简介
Circular definition of import alias 'hello'
导入的别名'APIClass'循环定义。
这种情况发生在两个或以上的模块相互引用同一变量名。
图示
demo
在同一目录下建以下三个文件。开启tslint。
// a.d.ts
import { hello } from '.';
export declare const v = hello;
// a.js
function hello() {
console.log(hello);
}
export { hello };
// index.js
export { hello } from './a';
在a.d.ts文件中如下所示将会报错:
总结
上面的文件就是a.d.ts
导入了index.js
中的变量hello
,index.js
导入了a.d.ts
中的hello
。所以导致Circular definition of import alias 'hello'
。
这里有一点细节:关于编译时和运行时谁是模块。
在index.js
文件中是从'./a'
中导入的hello
,这里的a
模块指的是a.d.ts
。如果同一目录下不存在a.d.ts
,编译时把a.js
当做导入模块,如果存在a.d.ts
,则把a.d.ts
当做导入模块。运行时只能把a.js
当做导入模块。