Error reporting when using babel to support es6 syntax; solve

  node.js, question

The code of a file is:

export const sqrt = Math.sqrt;
 export function square(x) {
 return x * x;
 bracket
 export function diag(x, y) {
 Return sqrt(square(x) plus square(y));
 bracket

The code for the other file is:

import { square, diag } from 'lib';
 console.log(square(11));  // 121
 console.log(diag(4, 3));

Error reported at runtime:

SyntaxError: import declarations may only appear at top level of a module
import { square, diag } from ‘lib’;

I just want to support es6 syntax, so I haven’t installed webpack yet.

The import statement must be at the top of the file, unlike require, which can be used at any time.