错误:无法找到预设" es2015"相对于具有节点js的目录

时间:2017-11-02 09:46:46

标签: node.js

nodejs version 8.9.0 && npm version 5.5.1。我想将es6与节点js一起用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

时遇到此错误

2 个答案:

答案 0 :(得分:3)

您运行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" } }]
  ]
}

答案 1 :(得分:0)

正确的示例是使用npm软件包名称,例如:

string[] collection = {"Zero", "One", "Two", "Three", "Four"};
var random = new Random();
var enumerableCollection = collection.OrderBy(e => random.NextDouble()).ToArray();

Console.WriteLine(enumerableCollection.ElementAt(0));
Console.WriteLine(enumerableCollection.ElementAt(0));
Console.WriteLine(enumerableCollection.ElementAt(0));
Console.WriteLine(enumerableCollection.ElementAt(0));
Console.WriteLine(enumerableCollection.ElementAt(0));