I was using babel with gulp to transform my JavaScript files and everything worked fine. But after I deleted my node_modules folder and ran npm install again, my build process started failing.
Now I get this error:
SyntaxError: main.js: Unexpected token (234:15)
The error shows this line causing problems:
233 | options,
> 234 | isAsync = true,
| ^
235 | cacheType = 'default',
236 | requestMethod = 'POST',
237 | requestHeaders = {},
What’s weird is that when I run babel main.js directly in the terminal, it compiles without any issues and produces the expected output.
Here’s my gulp setup:
const gulp = require('gulp');
const { babel } = require('gulp-load-plugins')();
gulp.task('compile', () => {
return gulp.src([
'src/main.js'
]).pipe(babel()).pipe(gulp.dest('dist'));
});
And my babel config:
{
"presets": ["es2016"],
"plugins": [
"transform-es2015-arrow-functions",
"transform-es2015-object-super",
"transform-es2015-parameters",
"transform-object-assign",
"transform-es2015-block-scoping",
"transform-es2015-shorthand-properties",
"transform-es2015-block-scoped-functions",
"transform-es2015-for-of",
"transform-es2015-destructuring",
["transform-es2015-classes", {"loose": true}],
["transform-es2015-spread", {"loose": true}],
["transform-es2015-template-literals", {"loose": true}]
]
}
Why would gulp-babel behave differently than the CLI version after reinstalling dependencies?