Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't find preset "es2015" relative to directory #93

Closed
littledu opened this issue Jul 23, 2016 · 15 comments
Closed

Couldn't find preset "es2015" relative to directory #93

littledu opened this issue Jul 23, 2016 · 15 comments

Comments

@littledu
Copy link

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.

@rbatllet
Copy link

rbatllet commented Jul 27, 2016

Have you installed these presets via npm?

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

@littledu
Copy link
Author

@rbatllet yes, I have installed .

@jmm
Copy link
Member

jmm commented Jul 27, 2016

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.

@panuhorsmalahti
Copy link

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)

@littledu
Copy link
Author

Thanks @panuhorsmalahti , I will try it next time.

@dominik0711
Copy link

@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

@rbatllet
Copy link

Try this:

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

@dominik0711
Copy link

@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.

@AlexanderKozhevin
Copy link

AlexanderKozhevin commented Mar 31, 2018

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. ✅

@onvno
Copy link

onvno commented Jul 6, 2018

gulp 3.9.x , preset:['env'] also see the problem. my system is mac OS, when the project on the desktop, execute the gulp babel command not work, error like 'Couldn't find preset "es2015" relative to directory' . but when migrate the project to Documents, the command can work normal.

Maybe Also need to fix the relative path with babel-preset-env

@yanickrochon
Copy link

This problem has not been resolved.

[15:38:56] Using gulpfile path/to/project/gulpfile.js
[15:38:56] Starting 'default'...
[15:38:56] 'default' errored after 31 ms
[15:38:56] Error in plugin "gulp-babel"
Message:
    Cannot find module '@babel/preset-es2017' from '/path/to/project'

@loganfsmyth
Copy link
Member

@yanickrochon We would need a reproducible example repository and ideally I'd recommend filing a new issue.

@altaf4web
Copy link

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

after installing this working fine now

@rbatllet Thanks

@ghost
Copy link

ghost commented Nov 19, 2018

@altaf4web Thanks. This works for me.

@dataf3l
Copy link

dataf3l commented Apr 11, 2019

Have you installed these presets via npm?

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

@rbatllet answer works! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests