Sunday 28 May 2017

error with babel when running node.js "Couldn't find preset "es2015" relative to directory"

Hi I'm trying to compile my project with babel. I'm getting this error when tried to run (I'm using babel as some code contain 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

Here is my 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"
  }
}

I have create my .babelrc

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

Anyone know what wrong with the configuration. I'm using babel with express.js.



via Lê Khánh Vinh

No comments:

Post a Comment