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.

Incorrect export when using ES6 export syntax

See original GitHub issue

Hi,

I’m currently making the switch to Babel 6 and running into the following problem, which might* be related to babelify.

Here’s my gulp-task:

let bify = browserify({
    entries    : './src/scripts/main.js',
    standalone : 'basicContext'
})

let transformer = babelify.configure({
    presets: ['es2015']
})

bify.transform(transformer)
    .bundle()
    .on('error', catchError)
    .pipe(source(name + '.min.js'))
    .pipe(buffer())
    .pipe(plugins.uglify())
    .on('error', catchError)
    .pipe(gulp.dest('./dist'))

main.js exports a function:

export default function(e, items, opts = {}) { … }

As I’m bundling this file as a standalone UMD module, I expected the variable basicContext to be a function. This was the case before I updated babelify and babel. Now basicContext is the following:

console.log(basicContext)
// {__esModule: true, default: function}

Best Tobias

  • Could be cased by Babel 6, too. It’s really not easy to find the dependency casing the issue.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
runemadsencommented, Nov 6, 2015

Also, for those of you interested, this is my terrible hack to change thi behavior in my gulp pipeline:

.pipe(replace("exports.default = MyFunction;", "module.exports = MyFunction;"))
1reaction
reintroducingcommented, Nov 23, 2015

I just wanted to follow up and say this only seems to be an issue when using Babel and requiring ES6 modules inside of ES5 modules. Just now made that realization, sorry for the noise :\

Read more comments on GitHub >

github_iconTop Results From Across the Web

Complete Guide For ES6 Import And Export Syntax Changes
This is invalid syntax of export in ES6 export { key1: value1, key2: value2 }. To import the things we exported as named...
Read more >
export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the ......
Read more >
Getting Unexpected Token Export - javascript - Stack Overflow
This error is suggesting that either webpack or babel are not working correctly, as export is only available in ES6, and those modules...
Read more >
ES6 Import And Export Cheatsheet - Yogesh Chavan
This is invalid syntax of export in ES6 export { key1: value1, key2: value2 }. To import the things we exported as a...
Read more >
Why is "export default var a = 1;" invalid syntax? - ES Discuss
From people.mozilla.org/~jorendorff/es6-draft.html#sec-exports, it seems that export default var a = 1; is not valid in es6. I wonder why that's the case.
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