ES6引入模块报错:SyntaxError: Cannot use import statement outside a module

ES6引入模块报错:SyntaxError: Cannot use import statement outside a module_第1张图片
import m1 from ‘./m1’;
^^^^^^

SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1071:16)
at Module._compile (internal/modules/cjs/loader.js:1121:27)
at Module._compile (D:\NODEJS\node_global\node_modules@babel\node\node_modules\pirates\lib\index.js:99:24)
at Module._extensions…js (internal/modules/cjs/loader.js:1177:10)
at Object.newLoader [as .js] (D:\NODEJS\node_global\node_modules@babel\node\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load (internal/modules/cjs/loader.js:900:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at Object. (D:\NODEJS\node_global\node_modules@babel\node\lib_babel-node.js:180:21)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
根据这个文档写的
https://nodejs.org/dist/latest-v10.x/docs/api/esm.html
应该修改扩展名为mjs

node --experimental-modules index.mjs

在这里插入图片描述

你可能感兴趣的:(模块化)