为了账号安全,请及时绑定邮箱和手机立即绑定

在使用babel支持es6语法时报错;求解

在使用babel支持es6语法时报错;求解

撒科打诨 2018-08-17 09:09:37
一个文件的代码是: export const sqrt = Math.sqrt;    export function square(x) {        return x * x;     }    export function diag(x, y) {        return sqrt(square(x) + square(y));     }另一个文件的代码是:import { square, diag } from 'lib'; console.log(square(11)); // 121console.log(diag(4, 3));运行时报错:SyntaxError: import declarations may only appear at top level of a moduleimport { square, diag } from 'lib';我只是想支持es6语法而已,所以还没安装webpack。
查看完整描述

1 回答

?
白猪掌柜的

TA贡献1893条经验 获得超10个赞

import语句必须在该文件的最上方,不像require可以随时用。


查看完整回答
反对 回复 2018-09-27
  • 1 回答
  • 0 关注
  • 652 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信