I get the following error when trying to use gulp-babel:
Error: Couldn\'t find preset \"es2015\" relative to directory \"/Users/username\"
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
The situation where I encounter this problem is that I have moved the files from xxx
to xxx/server
. And then under xxx/server
I will see the Error: Couldn't find preset "es2015" relative to directory "/Users/username/xxx"
error.
The real reason is that I have forgotten to move that .babelrc
file under xxx
. And after I move that .babelrc
to xxx/server
, the error goes away.
To fix this issue You should remove .babelrc (hidden) file from "/Users/username" directory.
From the docs you should now use @babel/preset-env
instead of any other preset
mention
The "env" preset has been out for more than a year now, and completely replaces some of the presets we've had/suggested earlier.
- babel-preset-es2015
- babel-preset-es2016
- babel-preset-es2017
- babel-preset-latest
- A combination of the above ^
yarn add @babel/preset-env
or
npm install @babel/preset-env
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.
You could try installing es2015
and stage-2
via
npm i babel-preset-es2015 --save
npm i babel-preset-stage-2 --save