nodejs version 8.9.0 && npm version 5.5.1。我想在节点js中使用es6,我的package.json.babelrc文件在任何主意之下!为什么我会得到这个错误

{
  "name": "something",
  "version": "1.0.1",
  "description": "some text",
  "main": "server.js",
  "scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "nodemon server.js --exec babel-node --preset es2015"
},
 "author": "xyz",
 "license": "MIT",
 "dependencies": {
  "babel-polyfill": "^6.26.0",
  "babel-preset-node6": "^11.0.0",
  "bcrypt": "^1.0.3",
  "body-parser": "^1.18.2",
  "express": "^4.16.2",
  "mongoose": "^4.12.6",
  "morgan": "^1.9.0"
 },
  "devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"nodemon": "^1.12.1",
"rimraf": "^2.6.2"
   }
 }


.babelrc文件

  {
   "presets": ["es2015"]
}


我在运行npm start时遇到此错误

最佳答案

您运行npm install吗?

我用您的package.json,.babelrc和全局安装的nodemon和babel-cli复制了消息。
我建议您全局卸载这些模块,以及可以在本地安装的所有其他模块,因为它们只会引起混乱。

我也建议

"start": "babel-watch server.js"


babel-preset-env而不是babel-preset-es2015

.babelrc

{
  "presets": [
    ["env", { "targets": { "node": "current" } }]
  ]
}

10-06 04:39