Error: Couldn't find preset "es2015" relative to directory "/Users/username"
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.
Related videos on Youtube
Brian Douglas
Updated on July 08, 2022Comments
-
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
-
thefourtheye over 8 yearsI think you need to pass a string in the
presets
array, like['es2015']
, I am not very sure though -
Brian Douglas over 8 years@thefourtheye Thanks but same issue as a string.
-
Andrei CACIO over 8 yearsYou didn't require gulp. Maybe that could be the cause
var gulp = require('gulp');
-
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 over 8 yearsDo 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 over 8 yearsCould 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 over 8 yearsI am using node 4.0 and babel 6
-
Brian Douglas over 8 yearsUpdated description with terminal output
-
Andrei CACIO over 8 yearsIt 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 over 8 yearsTry to uninstall the
node_modules
folder and reinstall fresh all packages -
Andrei CACIO over 8 yearsanother related post: stackoverflow.com/questions/34345573/…
-
Brian Douglas over 8 yearsThanks, unfortunately I have seen both of those. Will keep digging for a solution.
-
givemesnacks over 8 yearsLoading
babel-preset-es2015
explicitly as shown here solved my issue. -
yairr over 8 yearsMake sure .babelrc is configured correctly for babel 6. The format for 6 is
"presets": ["react", "es2015"],
-
Scott Stensland about 7 yearsthis 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 about 7 yearsalso worked for me using an absolute path to the "babel-preset-es2015" folder
-
overallduka almost 7 years+1 i found an
.babelrc
file in my root and this was the problem. the configbabelrc: false
seems not work, but when i delete everything works! -
Syed about 6 yearsnpm WARN deprecated [email protected]: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
-
Robert Oschler almost 6 yearsThis 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 over 5 yearsSaved my day! Thank you
-
Pawan over 4 yearsThanks a lot for this amazing solution.
-
Amgad over 3 yearsPerfect. this indeed is a very hidden issue. Solved it for me
-
JackChouMine about 3 yearsthis answer saves me.