情况描述
项目是默认使用webpack编译采用es6模块处理方案
出现了以下错误
以下是我写的测试类
A.ts
import {
B} from "./b.js";
export class A {
static getInstance() {
if (!this._instance) {
this._instance = new A();
}
return this._instance;
}
flush() {
console.log("----------------flush-------------------");
}
a() {
console.log("----------------flush-------------------"

本文介绍了在使用Webpack和ES6模块时遇到的'Uncaught ReferenceError: Cannot access '.' before initialization'错误。该错误源于A和B类之间的循环引用,特别是A类在初始化前尝试使用未定义的B类。通过分析Webpack生成的JavaScript代码,发现错误根源在于父类A在子类B之前被引用。解决方案是避免在父类中直接调用子类,而是采用属性赋值的方式处理循环引用。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



