npmgulp95% confidence\u2191 98

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' - Gulp

Full error message
Consider the following two files:

app.js

import Game       from './game/game';
import React      from 'react';
import ReactDOM   from 'react-dom';

export default (absPath) => {
  let gameElement = document.getElementById("container");

  if (gameElement !== null) {
      ReactDOM.render(
          <Game mainPath={absPath} />,
          gameElement
      );
  }
}

index.js

import App from './src/app';

The gulpfile.js

var gulp        = require('gulp');
var source      = require('vinyl-source-stream');
var browserify  = require('browserify');
var babelify    = require("babelify");
var watch       = require('gulp-watch');

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

The error:

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'

What is this error? What am I doing wrong?

Older versions of Babel came with everything out of the box. The newer version requires you install whichever plugins your setup needs. First, you'll need to install the ES2015 preset. npm install babel-preset-es2015 --save-dev Next, you need to tell babelify to use the preset you installed. return browserify({ ... }) .transform(babelify.configure({ presets: ["es2015"] })) ... Source

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/26b308a8d96593031ae1601b7bac6b45d562134d7f78d9b83fc6b654f18ce469
hash \u00b7 26b308a8d96593031ae1601b7bac6b45d562134d7f78d9b83fc6b654f18ce469
SyntaxError: &#39;import&#39; and &#39;export&#39; may appea… — DepScope fix | DepScope