I'm building a gulp script to process my ES2015 code, eventually with react, but it's simply not working. Uglify was throwing errors. (stream.js:74 throw er; // Unhandled stream error in pipe.) Once I looked at the build it was obvious that the ES2015 code was not being converted.
Most solutions to this issue concern a missing preset. I made sure to include babel-preset-es2015
. I have a .babelrc file that reads:
{
"presets": ["es2015", "react"]
}
My `gulpfile.babel.js won't run without it.
The file I'm trying to process is very simple:
// index.js
let bobby = "bobby"
console.log(bobby + ' Drink rum.')
When it's turned into an early JavaScript, the let
should be replaced by a var
. Maybe there is something wrong with my gulpfile.babel.js
?
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import runSequence from 'run-sequence';
import babel from 'gulp-babel';
// load all gulp-* plugins in node_modules
const plugins = gulpLoadPlugins()
gulp.task('default', () => {
runSequence('build', 'copy:index')
})
gulp.task('build', () => {
return gulp.src('src/**/*.js')
.pipe(babel())
.pipe(plugins.webpack())
// .pipe(plugins.uglify())
.pipe(plugins.rename('bundle.js'))
.pipe(gulp.dest('dist/'))
})
gulp.task('copy:index', () => {
gulp.src('src/index.html')
.pipe(gulp.dest('dist/'))
})
My gulp version is 3.9.1 My node version is 6.2.0
These are my dependencies so far:
"dependencies": {
"babel-core": "^6.17.0",
"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-register": "^6.16.3",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-filter": "^4.0.0",
"gulp-load-plugins": "^1.3.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^2.0.0",
"gulp-webpack": "^1.5.0",
"react": "^15.4.0-rc.4",
"react-dom": "^15.4.0-rc.4",
"run-sequence": "^1.2.2",
"webpack": "^1.13.2"
}
UPDATE: So I went and created a separate task just for Babel and it works. When I added on uglify and rename it works, but when I add Webpack, it has problems. Obviously, Webpack isn't playing nice. Has anyone else had this kind of trouble working with Webpack and gulp?