我正在尝试运行一个简单的脚本,该脚本会导入JS文件,然后执行控制台日志。我遇到的问题是import语句似乎在不给出任何错误的情况下停止了其余代码的运行。代码:
<script type="module">
import { Engine } from './engine/Engine.js'
(function() {
console.log('a');
})();
</script>
如果我注释掉导入行,则控制台日志可以正常工作。
编辑:Engine.js源
import { EngineError } from './errors/EngineError.js';
import { Screen } from './screen/Screen.js';
export class Engine {
constructor(reportErrors) {
// Set default values
this.Error = new EngineError(reportErrors);
this.FPS = 60;
this.Screen = new Screen(this);
}
}
编辑:输出的HTML
<html>
<head>
<link rel="stylesheet" href="./engine/engine.css">
</head>
<body>
<h1>Body</h1>
<canvas id="game"></canvas>
<script type="module">
import { Engine } from './engine/Engine.js'
//import { Screen } from './engine/screen/Screen.js';
(function() {
console.log('a');
})();
</script>
</body>
</html>