• Register
0 votes
1.3k views

Problem :

I am very new to gulp. I am facing following gulp error

My  gulpfile.js

var mygulp        = require('gulp');
var mysource      = require('vinyl-source-stream');
var mybrowserify  = require('browserify');
var mybabelify    = require("babelify");
var mywatch       = require('gulp-watch');

mygulp.task('make:game', function(){
  return mybrowserify({
    entries: [
      'index.js'
    ]
  })
  .transform('babelify')
  .bundle()
  .pipe(mysource('index.js'))
  .pipe(mygulp.dest('app/'));
})

gulp make:game
[13:09:48] Using gulpfile ~/Documents/ice-cream/gulpfile.js
[13:09:48] Starting 'make:game'...

events.js:154
      throw er; // Unhandled 'error' event
      ^
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'

I am unable to understand the error. How can I resolve this error?

7 5 2
3,870 points

1 Answer

0 votes

Solution :

The older versions of the Babel came with everything out of a box. But now the newer version requires you to install whichever plug-in your setup needs. So first, you will need to install a ES2015 preset by below command.

npm install babel-preset-es2015 --save-dev

Next, you just need to tell the babelify to use a preset you have just installed.

return browserify({ ... })
  .transform(babelify.configure({
    presets: ["es2015"]
  }))
  ...

 

OR

ESLint natively doesnt support this as this is against a spec. But if you use the babel-eslint parser then inside your eslint config file you can do this as shown below :

{
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module",
    "allowImportExportEverywhere": true
  }
}
9 7 4
38,600 points

Related questions

1 vote
1 answer 443 views
443 views
Problem : Currently I am trying to learn the Node, Webpack , Babel. I have recently joined a new project so need to learn these three technologies. Now I am facing below error while trying to build my project. “Module build failed (from ./node_modules/babel-loader/lib/index.js)”. ... .7.0", "webpack": "^4.17.1", "webpack-dev-server": "^3.1.7" } Please guide me in fixing above error.
asked Mar 31 morrisBson 3.2k points
0 votes
1 answer 68 views
68 views
Problem: Nowadays I am trying to use one plugin called "Simplebar" . I found it on GitHub. After downloading all the scripts and then looking at a simple.js script I found that it has the below error: "SyntaxError: import declarations may only appear at top level of a ... './simplebar.css' If I look in the browser debugger then I see the above error: Is there anyone who tried to use this plugin?
asked Aug 28 Raphael Pacheco 4.9k points
0 votes
1 answer 1.4K views
1.4K views
Problem : While I was trying to set up the React within Django project I came across below error ModuleBuildError in Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:\Users\jwilliam\Cebula3\cebula_react\assets\js\index.js: Support for the ... : [ "@babel/plugin-proposal-class-properties" ] } But the above error is still existed, How can I fix the error??
asked Jan 20 jwilliam 3.9k points