javascript - Babelify sourceType error when used programatically -


i using gulp, browserify , babelify compile source code es6 + jsx plain javascript.

my gulpfile.js looks like:

var gulp = require('gulp') var fs = require("fs") var browserify = require("browserify") var babelify = require("babelify")  gulp.task('es6',function(){   return browserify({ debug: true })     .transform(babelify.configure({       extensions: ['.es6']     }))     .require("./src/es6/app.es6", { entry: true })     .bundle()     .on("error", function (err) { console.log("error : " + err.message); })     .pipe(fs.createwritestream("./build/js/bundle.js")) }) 

the first lines of app.es6 is:

"use strict"  import react 'react' import menubar './menu' 

when run $ gulp es6, following error:

error : 'import' , 'export' may appear 'sourcetype: module' 

however not happen when use browserify's cli:

$ browserify src/es6/app.es6 -t babelify -o build/js/bundle.js --extension=.es6 

any thoughts on how problem can resolved?

the extensions:['.es6'] option needs added browserify's configuration:

browserify({ debug: true, extensions: ['.js', '.json', '.es6'] }) 

the entire gulpfile should this:

var gulp = require('gulp') var fs = require("fs") var browserify = require("browserify") var babelify = require("babelify")  gulp.task('es6',function(){   var extensions = ['.js','.json','.es6'];   return browserify({ debug: true, extensions:extensions })     .transform(babelify.configure({       extensions: extensions     }))     .require("./src/es6/app.es6", { entry: true })     .bundle()     .on("error", function (err) { console.log("error : " + err.message); })     .pipe(fs.createwritestream("./build/js/bundle.js")) }) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -