M
M
Maamoore2019-07-30 14:35:43
gulp.js
Maamoore, 2019-07-30 14:35:43

How to deal with the 'gulp-babel' plugin so that it works without errors?

I started learning JavaScript from the book "Learning JavaScript. 3rd Edition. O'Reilly". And despite the fact that I did everything exactly as it is written there, I get errors instead of the expected result.
SyntaxError in plugin "gulp-babel"
Message:
C:\Users\archi\test\lj\public\es6\test.js: Unexpected token, expected "," (4:44)
package.json

"devDependencies": {
    "@babel/cli": "^7.5.5",
    "@babel/core": "^7.5.5",
    "@babel/preset-env": "^7.5.5",
    "@babel/register": "^7.5.5",
    "babel": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "gulp": "^4.0.2",
    "gulp-babel": "^8.0.0"
  }

test.js
'use strict';
// es6 feature: block-scoped "let" declaration
const sentences = [
  { subject: 'JavaScript', verb: 'is', object: 'great' },
  { subject: 'Elephants', verb: 'are', object: 'large' },
];
// es6 feature: object destructuring
function say({ subject, verb, object }) {
  //es 6 feature: template strings
  console.log(`${subject} ${verb} ${object}`);
}
//es6 feature for..of
for(let s of sentences) {
  say(s);
}

gulpfile.babel.js
const gulp = require('gulp');
const babel = require('gulp-babel');

gulp.task('default', function() {
  
  gulp.src("es6/**/*.js")
    .pipe(babel())
    .pipe(gulp.dest("dist"));
    
  gulp.src("public/es6/**/*.js")
    .pipe(babel())
    .pipe(gulp.dest("public/dist"))
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question