JavaScript导出/导入不起作用

时间:2018-08-03 21:29:52

标签: javascript

我只想在另一个js文件上导入自定义js模块。

在html头上:

<script  src="Dictionary.js" type="module"></script>
<script type="text/javascript" src="Templates.js" ></script>

在模块上:

 var Dictionary=function() {...}
 export {Dictionary};

在js文件上:

import {Dictionary} from './Dictionary';

我收到这些错误

在Chrome上:

  

未捕获的SyntaxError:意外令牌{

在Firefox上

  

SyntaxError:导入声明只能出现在   模块

这两个文件位于同一文件夹中。

1 个答案:

答案 0 :(得分:1)

导入时,请勿添加“ .js”

import {Dictionary} from 'Dictionary';

请参阅文档here