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.

Webpack2, export class in modules

See original GitHub issue

Hello !

In a module, some export doesn’t works:

module a, index.js

export default class A {}
export class B{}

export const c = 'c';

Generated:

function(module, exports, __webpack_require__) {

    "use strict";
    'use strict';

    class A {}
    class B {}

    var c = 'c';/* unused harmony export c */

/***/ 

c is detected, but not A or B.

It works like this:

class A {}
export default A;

Generated:

/***/ function(module, exports, __webpack_require__) {

    "use strict";
    'use strict';

    class A {}
    /* harmony default export */ exports["a"] = A;
    class B {}

    var c = 'c';/* unused harmony export c */


/***/ },

It works when it is in my app, however (when it’s not in a module):

export default class A{};

Generated:

/***/ function(module, exports, __webpack_require__) {
    var A = class A {};

    /* harmony export */ Object.defineProperty(exports, "a", {configurable: false, enumerable: true, get: function() { return A; }});

/***/

Can you help me ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

1reaction
aeosynthcommented, Jun 4, 2016

@christophehurpeau posted a workaround:

class A {}
export default A;
0reactions
SurealCerealcommented, May 28, 2016

I seem to be experiencing this issue too. I am not using Babel - I am trying to use pure ES6 modules generated by Typescript. For some reason some classes are not exported.

I see lines like /* harmony import */WEBPACK_IMPORTED_MODULE_1__shared_custom_models_SomeModule[“SomeClass”] but that property “SomeClass” was not previously defined. Is there a known workaround?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Export class as a module in webpack - Stack Overflow
Firstly you should export the class. export class myClass { // ... } And for browsers you should use IIFE or UMD format:...
Read more >
Export ES6 Class Globally with webpack | Sean C Davis
To make this class globally available I have to adjust my webpack config slightly: webpack.config.js const path = require("path"); module.exports = {
Read more >
Package exports - webpack
The exports field in the package.json of a package allows to declare which module should be used when using module requests like import...
Read more >
Module Methods - webpack
Statically import the export s of another module. import MyModule from './my-module.js'; import { NamedExport } ...
Read more >
ECMAScript Modules - webpack
Webpack supports processing ECMAScript Modules to optimize them. Exporting. The export keyword allows to expose things from an ESM to other modules: export...
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