Tree-Shaking getting rid of reexport line when it shouldn’t

I’m submitting a bug report

Webpack version:
2.x

Please tell us about your environment:
Windows 10

Current behavior:
It’s not re-exporting a module because it thinks it’s not being used, when it is.

Expected/desired behavior:
It should re-export the module

I have the following file structure:

first/
    index.js
    second/
        index.js
        thing.js
index.js
main.js

index.js:

export * from './first';

main.js:

import {wtf} from './';

console.log(wtf);

first/index.js:

export * from './second';

first/second/index.js:

export * from './thing';

first/second/thing.js:

export const wtf = 'wtf';

The output from webpack is:

webpackJsonp([0,2],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0____ = __webpack_require__(4);

console.log(__WEBPACK_IMPORTED_MODULE_0____["a" /* wtf */]);


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

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__second__ = __webpack_require__(2);
/* harmony namespace reexport */ for(var __WEBPACK_IMPORT_KEY__ in __WEBPACK_IMPORTED_MODULE_0__second__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(exports, key, function() { return __WEBPACK_IMPORTED_MODULE_0__second__[key]; }) }(__WEBPACK_IMPORT_KEY__));



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

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__thing__ = __webpack_require__(3);
/* harmony namespace reexport */ for(var __WEBPACK_IMPORT_KEY__ in __WEBPACK_IMPORTED_MODULE_0__thing__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(exports, key, function() { return __WEBPACK_IMPORTED_MODULE_0__thing__[key]; }) }(__WEBPACK_IMPORT_KEY__));



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

"use strict";

/* harmony export */ __webpack_require__.d(exports, "wtf", function() { return wtf; });var wtf = 'wtf';


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

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__first__ = __webpack_require__(1);
/* unused harmony namespace reexport */



/***/ },
/* 5 */,
/* 6 */
/***/ function(module, exports, __webpack_require__) {

module.exports = __webpack_require__(0);


/***/ }
],[6]);
//# sourceMappingURL=main.map

In the 4 module above, it should not have /* unused harmony namespace reexport */. It should actually re-export.

Author: Fantashit

2 thoughts on “Tree-Shaking getting rid of reexport line when it shouldn’t

Comments are closed.