{"id":577,"hash":"26b308a8d96593031ae1601b7bac6b45d562134d7f78d9b83fc6b654f18ce469","pattern":"SyntaxError: &#39;import&#39; and &#39;export&#39; may appear only with &#39;sourceType: module&#39; - Gulp","full_message":"Consider the following two files:\n\napp.js\n\nimport Game       from './game/game';\nimport React      from 'react';\nimport ReactDOM   from 'react-dom';\n\nexport default (absPath) => {\n  let gameElement = document.getElementById(\"container\");\n\n  if (gameElement !== null) {\n      ReactDOM.render(\n          <Game mainPath={absPath} />,\n          gameElement\n      );\n  }\n}\n\nindex.js\n\nimport App from './src/app';\n\nThe gulpfile.js\n\nvar gulp        = require('gulp');\nvar source      = require('vinyl-source-stream');\nvar browserify  = require('browserify');\nvar babelify    = require(\"babelify\");\nvar watch       = require('gulp-watch');\n\ngulp.task('make:game', function(){\n  return browserify({\n    entries: [\n      'index.js'\n    ]\n  })\n  .transform('babelify')\n  .bundle()\n  .pipe(source('index.js'))\n  .pipe(gulp.dest('app/'));\n});\n\nThe error:\n\ngulp make:game\n[13:09:48] Using gulpfile ~/Documents/ice-cream/gulpfile.js\n[13:09:48] Starting 'make:game'...\n\nevents.js:154\n      throw er; // Unhandled 'error' event\n      ^\nSyntaxError: 'import' and 'export' may appear only with 'sourceType: module'\n\nWhat is this error? What am I doing wrong?","ecosystem":"npm","package_name":"gulp","package_version":null,"solution":"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.\n\nnpm install babel-preset-es2015 --save-dev\n\nNext, you need to tell babelify to use the preset you installed.\n\nreturn browserify({ ... })\n  .transform(babelify.configure({\n    presets: [\"es2015\"]\n  }))\n  ...\n\nSource","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/40029113/syntaxerror-import-and-export-may-appear-only-with-sourcetype-module-g","votes":98,"created_at":"2026-04-19T04:51:22.574234+00:00","updated_at":"2026-04-19T04:51:22.574234+00:00"}