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.

how i can use export default and require (webpack2)

See original GitHub issue

t.js:

export default class {

}

index.js:

const cls = require("./t");

export default class PreferenceOmitDialogCondition extends cls {

}

i know that i can require(“./t”).default , but i have many old code and it difficult change.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

23reactions
sokracommented, Jun 15, 2016

Don’t mix babel es6 module handling with webpacks. webpack allows to mix CommonJs and ES6 modules this way:

// es6.js
import something from "./commonjs";

export default "xyz";
export var abc = "abc";
// commonjs.js
var xyz = require("./es6").default;
var abc = require("./es6").abc;

module.exports = "something";

Don’t use the add-module-exports plugin.

PS: exports.a is used instead of exports.default when a es6 module is only imported via es6 imports. webpack mangles the export names.

15reactions
sokracommented, Jun 16, 2016

The code is wrong. Change it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module Methods - webpack
Labeled Modules. The internal LabeledModulesPlugin enables you to use the following methods for exporting and requiring within your modules: export label.
Read more >
Fixing export default on Webpack when bundling a library
Required workaround to properly distribute a library built with Typescript, Babel and Webpack. As my latest project is a standalone library, ...
Read more >
How do I expose a javascript module's default export object ...
You can use ProvidePlugin in order to do so. At first you need to make alias for the file you want to be...
Read more >
wordpress/library-export-default-webpack-plugin | Block Editor ...
Webpack plugin for exporting default property for selected libraries which use ES6 Modules. Implementation is based on the Webpack's core plugin ...
Read more >
How to transpile ES modules with webpack and Node.js
Also note that we can have default exports with ESM. ... Now, we need to compile our ES2015 code to ES5 so that...
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