Error: Couldn't find preset "es2015" relative to directory "/Users/username"

I get the following error when trying to use gulp-babel:

Error: Couldn't find preset "es2015" relative to directory "/Users/username"

I have the es2015 preset installed globally and locally so can't see why this would be an issue.

Below is my gulp set up and package.json.

var babel = require('gulp-babel');
var es2015 = require('babel-preset-es2015');

gulp.task('babel', function() {
    return gulp.src('./app/main.js')
    .pipe(babel({
        presets: [es2015]
    }))
    .pipe(gulp.dest('dist'));
});

Package.json

  "devDependencies": {
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-es2015-node5": "^1.1.1",
    "browser-sync": "^2.11.0",
    "gulp": "^3.9.0",
    "gulp-babel": "^6.1.1",
    "gulp-stylus": "^2.2.0"
  }

I am using node v5.1.0 and babel v6.4.0

Here is the terminal ouput

terminal output


Solution 1:

You only need to install babel-preset-es2015:

CLI usage example:

npm install babel-cli babel-preset-es2015

Solution 2:

To fix this issue You should remove .babelrc (hidden) file from "/Users/username" directory.

Solution 3:

the "es2015" in :

    .pipe(babel({
        presets: ['es2015']
    }))

is actually a path - so if you don't have the preset in the /Users/username/es2015 directory you have to point exactly to it like for instance:

.pipe(babel({
    presets: ['../../gulp/node_modules/babel-preset-es2015']
}))

it worked for me

Solution 4:

I just used this exact gulpfile.js

var babel = require('gulp-babel');
var es2015 = require('babel-preset-es2015');
var gulp = require('gulp');

gulp.task('babel', function() {
    return gulp.src('./app/main.js')
    .pipe(babel({
        presets: [es2015]
    }))
    .pipe(gulp.dest('dist'));
});

and it worked for me. I only installed babel, babel-preset-es2015 and gulp-babel.

Solution 5:

Check if you have .babelrc file in the root folder of your Project. If not create .babelrc file and add the following:

{
  "presets": ["es2015"]
}

It fixed the issue.