运行node.js时出现babel错误`无法找到相对于目录`的预设“es2015”

时间:2017-05-28 07:39:01

标签: node.js express babel

我正在尝试使用babel编译我的项目。尝试运行时出现此错误(我正在使用babel,因为某些代码包含ES6

/usr/local/bin/node -r babel-register /Volumes/Elements/Learning/Node/Project/building-apis-with-nodejs-master/ntask-api/index.js
/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
        throw e;
        ^

Error: Couldn't find preset "es2015" relative to directory "/Volumes/Elements/Learning/Node/Project/building-apis-with-nodejs-master/ntask-api"
    at /Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (native)
    at OptionManager.resolvePresets (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at compile (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-register/lib/node.js:103:45)
    at loader (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-register/lib/node.js:144:14)
    at Object.require.extensions.(anonymous function) [as .js] (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:488:32)

Process finished with exit code 1

这是我的package.json

{
  "name": "ntask-api",
  "version": "1.0.0",
  "description": "Task list API",
  "main": "index.js",
  "scripts": {
    "start": "npm run apidoc",
    "clusters": "babel-node clusters.js",
    "test": "NODE_ENV=test mocha test/**/*.js",
    "apidoc": "apidoc -i routes/ -o public/apidoc"
  },
  "apidoc": {
    "name": "Node Task API - Documentation",
    "template": {
      "forceLanguage": "en"
    }
  },
  "author": "Vic",
  "dependencies": {
    "bcrypt": "^0.8.5",
    "body-parser": "^1.15.0",
    "compression": "^1.6.1",
    "consign": "^0.1.2",
    "cors": "^2.7.1",
    "express": "^4.13.4",
    "helmet": "^1.1.0",
    "jwt-simple": "^0.4.1",
    "morgan": "^1.6.1",
    "passport": "^0.3.2",
    "passport-jwt": "^2.0.0",
    "sequelize": "^3.19.2",
    "sqlite3": "^3.1.1",
    "winston": "^2.1.1"
  },
  "devDependencies": {
    "apidoc": "^0.15.1",
    "babel-cli": "^6.24.1",
    "babel-preset-env": "^1.5.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-register": "^6.5.2",
    "chai": "^3.5.0",
    "mocha": "^2.4.5",
    "supertest": "^1.2.0"
  }
}

我创建了.babelrc

{
  "presets": ["env","es2015"]
}

任何人都知道配置有什么问题?我正在babel使用express.js

0 个答案:

没有答案