在我的packages.json中,我有:
"scripts": {
"start": "babel-node ./server/server.js --presets es2016,stage-2"
},
server.js有:import path from 'path';
在顶部。
运行npm start
,我收到错误:
/Users/*********/nomad/server/server.js:1
(function (exports, require, module, __filename, __dirname) { import path from 'path';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at loader (/Users/**********/nomad/node_modules/babel-register/lib/node.js:146:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/**********/nomad/node_modules/babel-register/lib/node.js:156:7)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Function.Module.runMain (module.js:590:10)
at /Users/**********/nomad/node_modules/babel-cli/lib/_babel-node.js:151:24
at Object.<anonymous> (/Users/*********/nomad/node_modules/babel-cli/lib/_babel-node.js:152:7)