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.

Dealing with ES6 export

See original GitHub issue
/* foobar.js */

// ES6 export
const foobar = {
  foo: 'bar'
}
export default foobar;

// is equivalent to
module.exports = {
  default: foobar
}
/* foobar-log.js */

console.log(foobar);

So if I import foobar-log.js with imports-loader

import 'imports?foobar=./foobar!./foobar-log'

It gives object with default. It seems there’re no way toget just { foo: bar }.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
getsnoopycommented, Jan 25, 2017

@SpaceK33z , #35 allows something like imports?foobar.default=foobar which would result in foobar.default = require('foobar'), but what we want in this case is something like imports?foobar=foobar.default to result in var foobar = require('foobar').default, since the ES6 transpilation will end up nesting the default export of the module under the default property of foobar’s exported object.

I tried to do something like that with v0.7.0 without luck. That makes sense though, considering . is an allowed character in file names, so there’s no way to know whether it’s part of the filename or property notation.

Having an easy way to import default exports and/or named exports would be nice.

1reaction
wildcardcommented, Apr 25, 2017

@getsnoopy try this e.g. imports-loader?{default:Auth0Lock}=auth0-lock!angular-lock using a ES2015 destructor will solve the problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES6 Modules and How to Use Import and Export in JavaScript
You can export members one by one. What's not exported won't be available directly outside the module: export const myNumbers = [ ...
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 >
ES6 | Import and Export - GeeksforGeeks
ES6 | Import and Export · Example 1: Create a file named export.js and write the below code in that file. export let...
Read more >
ES6 Import And Export Cheatsheet - Yogesh Chavan
In ES6, data declared in one file is not accessible to another file until it is exported from that file and imported into...
Read more >
16. Modules - Exploring JS
16.3 The basics of ES6 modules #. There are two kinds of exports: named exports (several per module) and default exports (one per...
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