ashwintastic
ashwintastic

Reputation: 2312

Error: Couldn't find preset "es2015" relative to directory with node js

nodejs version 8.9.0 && npm version 5.5.1. I want to use es6 with node js my package.json and .babelrc file is below any idea !! why I'm gettimg this error

{
  "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 file

  {
   "presets": ["es2015"]
}

I'm getting this error when I'm running npm start

Upvotes: 1

Views: 2554

Answers (2)

shivaay
shivaay

Reputation: 1

The correct example would be to use the npm package names, e.g.:

presets: ["babel-preset-es2015", "babel-preset-es2016", "babel-preset-es2017"].map(require.resolve)

Upvotes: 0

lecstor
lecstor

Reputation: 5707

have you run npm install?

I replicated the message with your package.json, .babelrc, and globally installed nodemon and babel-cli. I'd recommend you uninstall those modules globally, and any others that you can install locally instead, as they will just lead to confusion.

I'd also recommend

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

and babel-preset-env instead of babel-preset-es2015.

.babelrc

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

Upvotes: 3

Related Questions