我正在使用webpack + es6来构建我的文件。我在Math.js中导出模块,然后在Main.js中进行导入。
在后者中,我使用了该模块进行计算,然后在调试器中设置了一个停止点。前者可以正常工作,但当我尝试在控制台中使用它时,它未被定义。
范围是相同的-为什么控制台中未定义该模块?
// Math.js
export function sum(x, y) {
return x + y;
}
export var pi = 3.141593;
// Main.js
import * as mathTest from "./Math.js";
console.log("2π = " + mathTest.sum(mathTest.pi, mathTest.pi));
debugger
// Output
// The statement from the file writes properly but the debugger fails (but <this> is the same)
pi
在sum
之后定义的,虽然只是一个猜测... - Ivan Satsiuk