• 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 844 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 223 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 23 views
Problem: uncaught syntaxerror: cannot use import statement outside a module.
asked Feb 15 Ethan ross 1.8k points
0 votes
1 answer 4 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.5k points
0 votes
1 answer 3 views
Problem : failed to load external module babel register
asked 4 days ago Shovo210 3.1k points
0 votes
1 answer 22 views
Problem: gulp' is not recognized as an internal or external command, operable program or batch file.
asked Feb 18 Lucky Guy 1.4k points
0 votes
1 answer 2.2K 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, 2020 jwilliam 3.9k points
0 votes
1 answer 17 views
Problem: scripts may close only the windows that were opened by it.
asked Feb 20 charles mathews 3.8k points
0 votes
2 answers 113 views
Problem : I am using the reactjs. When I run my code below my browser says: Uncaught TypeError: Super expression must either be null or a function, not undefined Any clues at all as to what is wrong with my code? First the line used to compile the code as below : ... var React = require('react'); class HelloMessage extends React.Component {   render() {     return <div>Hello World</div>;   } }
asked Jan 23, 2020 jwilliam 3.9k points