question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Not sure what’s going on, but this message just started showing up…

“SyntaxError: ‘import’ and ‘export’ may appear only with ‘sourceType: module’”

Here’s the relevant bit from my gulp file:

'use strict';

var gulp = require('gulp'),
    notify = require("gulp-notify"),
    babelify = require('babelify'),
    browserify = require('browserify'),
    browserSync = require('browser-sync'),
    source = require('vinyl-source-stream'),
    uglify = require('gulp-uglify'),
    buffer = require('vinyl-buffer');

var vendors = [
  'jquery',
  'moment',
  'd3',
  'queue-async',
  'react',
  'react-dom',
  'react-bootstrap',
  'react-infinite',
  'lodash',
  'rc-switch',
  'rc-slider',
  'he',
  'react-debounce-input',
  'react-swipe-views',
  'react-modal',
];


gulp.task('app', function () {
    var stream = browserify({
            entries: ['./app/app.jsx'],
            transform: [babelify],
            debug: false,
            extensions: ['.jsx'],
            fullPaths: false
        });

    vendors.forEach(function(vendor) {
        stream.external(vendor);
    });

    return stream.bundle()
                 .pipe(source('build.min.js'))
                 .pipe(buffer())
                 .pipe(uglify())
                 .pipe(gulp.dest('build/js'))
                 .pipe(notify("Successfully built build.min.js file!"));

});

I’m not sure what happened, but things were fine just a few days ago. Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

58reactions
zertoshcommented, Nov 2, 2015

You upgraded to babelify 7.0, which uses the new babel 6.0, and you’re missing options. Please checkout the README.

38reactions
zertoshcommented, Dec 22, 2015

I’m sorry you feel that way. I offered to personally debug your issue if you provided me with some code. I didn’t meant to offend. Please remember that we’re all volunteers here and just trying to make cool things.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'import' and 'export' may appear only with 'sourceType: module ...
In my case, I was getting this error with browserify and babelify when trying to compile JS files that imported TypeScript files, e.g....
Read more >
Babelify error: 'import' and 'export' may appear only ... - GitHub
It is failing with the error: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (4819:0) while parsing ...
Read more >
'import' and 'export' may appear only with 'sourceType: module ...
ParseError: 'import' and 'export' may appear only with 'sourceType: module' It happens just after the npm initialization and Budo installation. ...
Read more >
SyntaxError: 'import' and 'export' may appear only ... - YouTube
JavaScript : SyntaxError : ' import' and 'export' may appear only with 'sourceType : module ' - Gulp [ Gift : Animated Search...
Read more >
SyntaxError: 'import' and 'export' may appear only ... - YouTube
react-native: SyntaxError : ' import' and 'export' may appear only with 'sourceType : module ' (1:0)Thanks for taking the time to learn more....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found