在Firefox中,ES2015导入不起作用(甚至在顶级) [英] ES2015 import doesn't work (even at top-level) in Firefox

查看:198
本文介绍了在Firefox中,ES2015导入不起作用(甚至在顶级)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些是我的示例文件:

 <!DOCTYPE html> 
< html>
< head>
< title>测试< / title>
< script src =t1.js>< / script>
< / head>
< body>< / body>
< / html>

t1.js:

  import'from t2.js'; 

t2.js:

  export const Test = console.log(Hello world); 

当我在Firefox 46中加载页面时,它返回SyntaxError:import声明可能只出现在顶部一个模块的级别 - 但我不知道进口语句可以在这里获得多少顶级。这个错误是一个红色的鲱鱼,只是不支持导入/导出?

解决方案



如果要导入ES6模块,我建议使用transpiler(例如, babel )。


These are my sample files:

<!DOCTYPE html>
<html>
<head>
  <title>Test</title>
  <script src="t1.js"></script>
</head>
<body></body>
</html>

t1.js:

import Test from 't2.js';

t2.js:

export const Test = console.log("Hello world");

When I load the page in Firefox 46, it returns "SyntaxError: import declarations may only appear at top level of a module" - but I'm not sure how much more top-level the import statement can get here. Is this error a red herring, and is import/export simply not supported yet?

解决方案

From import on MDN:

This feature is not implemented in any browsers natively at this time. It is implemented in many transpilers, such as the Traceur Compiler, Babel or Rollup.

Browsers do not support import.

Here is the browser support table:

If you want to import ES6 modules, I would suggest using a transpiler (for example, babel).

这篇关于在Firefox中,ES2015导入不起作用(甚至在顶级)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆