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

75,674

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.

Share:
75,674

Related videos on Youtube

Brian Douglas
Author by

Brian Douglas

Updated on July 08, 2022

Comments

  • Brian Douglas
    Brian Douglas almost 2 years

    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

    • thefourtheye
      thefourtheye over 8 years
      I think you need to pass a string in the presets array, like ['es2015'], I am not very sure though
    • Brian Douglas
      Brian Douglas over 8 years
      @thefourtheye Thanks but same issue as a string.
    • Andrei CACIO
      Andrei CACIO over 8 years
      You didn't require gulp. Maybe that could be the cause var gulp = require('gulp');
    • Brian Douglas
      Brian Douglas over 8 years
      @AndreiCacio I have included gulp it just isnt in the code snippet. I have only included the code relevant to the babel compiler.
    • loganfsmyth
      loganfsmyth over 8 years
      Do you happen to have a .babelrc file in your home directory? Since that is where it is looking for the preset, that means that is where the configuration is coming from.
  • Brian Douglas
    Brian Douglas over 8 years
    Could you tell me your version of babel and node. I have the same set up as you can see. but still that same error
  • Andrei CACIO
    Andrei CACIO over 8 years
    I am using node 4.0 and babel 6
  • Brian Douglas
    Brian Douglas over 8 years
    Updated description with terminal output
  • Andrei CACIO
    Andrei CACIO over 8 years
    It might be a windows related issue or smth like that. I have found a similar thread that you can check out: github.com/laravel/elixir/issues/354 maybe it will shine a light on the problem.
  • Andrei CACIO
    Andrei CACIO over 8 years
    Try to uninstall the node_modules folder and reinstall fresh all packages
  • Andrei CACIO
    Andrei CACIO over 8 years
  • Brian Douglas
    Brian Douglas over 8 years
    Thanks, unfortunately I have seen both of those. Will keep digging for a solution.
  • givemesnacks
    givemesnacks over 8 years
    Loading babel-preset-es2015 explicitly as shown here solved my issue.
  • yairr
    yairr over 8 years
    Make sure .babelrc is configured correctly for babel 6. The format for 6 is "presets": ["react", "es2015"],
  • Scott Stensland
    Scott Stensland about 7 years
    this solved it for me ... WoW what a terrible error message : Error: Couldn't find preset "es2015" relative to directory "/path/to/node/package/attemping/to/install" ... especially painful when trying to install some random npm package which uses gulp and babel
  • valkalon
    valkalon about 7 years
    also worked for me using an absolute path to the "babel-preset-es2015" folder
  • overallduka
    overallduka almost 7 years
    +1 i found an .babelrc file in my root and this was the problem. the config babelrc: false seems not work, but when i delete everything works!
  • Syed
    Syed about 6 years
    npm WARN deprecated [email protected]: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
  • Robert Oschler
    Robert Oschler almost 6 years
    This may seem overly simplistic, so I'm only adding it as a comment, but make sure you spell everything right. I had the label as 'es2105' with the digits transposed and it had me scratching my head for a while.
  • Mehrnoosh
    Mehrnoosh over 5 years
    Saved my day! Thank you
  • Pawan
    Pawan over 4 years
    Thanks a lot for this amazing solution.
  • Amgad
    Amgad over 3 years
    Perfect. this indeed is a very hidden issue. Solved it for me
  • JackChouMine
    JackChouMine about 3 years
    this answer saves me.