迁移到提升导入

问题描述 投票:0回答:0

所以我最近已经转向基于 esm 的 swc 模块。一切都很好,除了我的应用程序依赖于没有被提升到顶部的导入语句,基本上在我的

index.ts
中我导出了一个在导入模块中使用的变量。

// index.ts

export const a = {foo: "bar"};
import {b} from "./blah/b";
// b.ts

import {a} from "../index";
export const b = a.foo;

所以当我运行这段代码时,我得到了

ReferenceError: Cannot access 'a' before initialization
。因为导入在
index.ts
中被吊到最上面。这意味着
b.ts
代码首先执行。我如何在不返回 CommonJS 的情况下解决这个问题?我真的受够了这种导入和导出的东西,这真是一团糟。

typescript ecmascript-6 es6-modules circular-dependency
© www.soinside.com 2019 - 2024. All rights reserved.