gulp-babel: Couldn't find preset "es2015" relative to directory

I use gulp-babel in electron,I have all the dependencies installed. the code is :

function compileJs(cb) {
        gulp.src(paths.src.js)
            .pipe(babel({
                presets: ['es2015', 'stage-2']
            }))
            .pipe(uglify())
            .pipe(gulp.dest(paths.tmp.js))      
    }

When I was developing, everything was all right. Bug When I packed electron app and run , it throw:

events.js:154 Uncaught Error in plugin 'gulp-babel'
Message:
    Couldn't find preset "es2015" relative to directory "/Users/user/WeFlow_workspace/WeFlow-example/src/js"

I don’t know whose fault it is. Can you help me? Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 9
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Have you installed these presets via npm?

babel-preset-es2015
babel-preset-stage-2

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)

Hello @littledu, you may want to just resolve the preset location yourself in your build script, example:

presets: ['es2015', 'stage-2'].map(require.resolve)

In any case, this isn’t actually an issue with gulp-babel, which is just a wrapper. The best places for you to get further help with this are listed in Babel’s README.

@rbatllet yes, I have installed .

npm install babel-preset-es2015 babel-preset-stage-2 --save

after installing this working fine now

@rbatllet Thanks

@panuhorsmalahti I try to transpile from es6 to es5 with gulpv4 and CLIv1.2.2. My gulpfile-task is the following:

gulp.task('babelify', () => {
  gulp.src([`${global.config.source}/**/*.js`,
            `!${global.config.source}/js/3rd/**/*`,
            `!${global.config.source}/libs/**/*`])
    .pipe(babel({ presets: ['babel-preset-es2015'].map(require.resolve) }))
    .pipe(gulp.dest(dist('js')));
});

I did receive the following error:

Couldn't find preset "es2015" relative to directory 
"/Users/tester/Projects/TestProject/src"

Do you have any idea how to solve this issue?

Thanks in advance

For some reason in my case, I got the same error. I installed everything. But it try to find preset-0 relative to the code path which is wrong.

/Users/alexanderkozhevin/Desktop/new_frontend/src/app/virtus.js: Cannot find module 'babel-preset-stage-0' from '/Users/alexanderkozhevin'

The funny thing. Error disappeared when I created .babelrc file with simple config. ✅

@rbatllet Your suggestion was my first implementation with the same error output! This was the reason why I have found this thread. I have in mind that with gulp version < 4.0.0 this wasn’t a problem at all. But I’m not pretty sure. But why does gulp-babel takes ${global.config.source}, which in real is /Users/tester/Projects/TestProject/src , as the base/search path for the es2015 preset? This makes no sense at all.