无法在模块外部使用import语句 [英] Cannot use import statement outside a module
本文介绍了无法在模块外部使用import语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在纯JavaScript中使用类,因此遇到错误未捕获的SyntaxError:无法在模块外部使用import语句",并且无法解决.
I'm trying to use classes in pure JavaScript, so I'm facing the error "Uncaught SyntaxError: Cannot use import statement outside a module" and can't solve it.
File1.js-主文件
File1.js - Main file
import example from "./file2";
var test = new example();
File2.js-类文件
File2.js - Class file
export default class example {
constructor() {
console.log("hello world");
}
}
推荐答案
使用type="module"
添加文件:
<script src="file1.js" type="module"></script>
这篇关于无法在模块外部使用import语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文