Webpack2, export class in modules
See original GitHub issueHello !
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:
- Created 7 years ago
- Reactions:4
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@christophehurpeau posted a workaround:
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?