• Register
0 votes

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: [

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

      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

Please log in or register to answer this question.

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({ ... })
    presets: ["es2015"]



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 989 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, 2020 morrisBson 3.2k points
0 votes
1 answer 107 views
Problem: uncaught syntaxerror: cannot use import statement outside a module.
asked Feb 15 Ethan ross 2.7k points
0 votes
1 answer 7 views
Problem: I'm new to web programming, I was trying a very simple example in order understand how it works. html file <html> <head> <meta charset="ISO-8859-1"> <script type="text/javascript" src="/static/js/AddButton.js"></script> <script type="text/javascript" src ... Loading failed for the module with source . the client can't even load the scripts.
asked May 1 ochena 23.3k points
0 votes
1 answer 503 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, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 133 views
Problem : failed to load external module babel register
asked Feb 25 Sabbir Hossain 14.6k points
0 votes
1 answer 18 views
Problem Hi Kodlogs communitiy, I am confused about var const and let variables in JavaScript. Could please someone shed some light on it ?
asked Jan 22 alexh 2.6k points
0 votes
1 answer 8 views
Problem: Please can anyone tell me the right procedure to do it? expected this to be used by class method
asked Apr 7 Ifra 36.4k points
0 votes
1 answer 24 views
Problem : I cannot call a bind from onchanged.I'm making list using onsenui and react.I get this : Typeerror: cannot read property 'bind' of undefined I couldn't figure out.... Does anyone can solve this?
asked Mar 21 Sabbir Hossain 14.6k points
1 vote
1 answer 57 views
Problem : I'm using React with ES7.I type anything in the input box of AuthorForm and I'm getting this error : Uncaught TypeError: Cannot read property 'state' of undefined HELP! I need help understanding this error. Thank you in Advance!
asked Mar 20 Sabbir Hossain 14.6k points
0 votes
1 answer 4 views
Problem: I want to find out that task which will be called in gulp by default, help me here .
asked Apr 26 salim1 60.6k points