Skip to content

Missing member name of ES6 module export when use dll reference with it's dependence. #2876

@mc-zone

Description

@mc-zone

I'm submitting a bug report
Missing member name when use dll reference with it's dependence

Webpack version:
2.1.0-beta.20

Please tell us about your environment:
OSX 10.x / Linux / Windows 10

Current behavior:
wrong member name when try to import dependence of dll reference.

Expected/desired behavior:
Import a member from module which is dll's dependence.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.

Say there are three files:

  • common.js: For the dll.
  • index.js: the entry of pages.
  • lib.js: Be referenced both of common.js and index.js.

Codes like:
common.js:

import { libFn } from './lib';

export function commonFn(){
  libFn()
}

index.js:

import { libFn } from './lib';

console.log( 'index', libFn() )

lib.js:

export function libFn(){
  return 'libFn'
}

Then there are my webpack config:

webpack.dll.config.js:

var webpack = require('webpack');
var path = require('path');

module.exports = {
  entry:{
    'common':['./common.js']
  },
  output:{
    path: path.resolve(__dirname,'./output'),
    filename:'[name].dll.js',
    library:'[name]',
    pathinfo:true
  },
  plugins:[
    new webpack.DllPlugin({
      path:path.resolve(__dirname, './output/[name]-manifest.json'),
      name:"[name]"
    })
  ]
};

webpack.config.js:

var webpack = require('webpack');
var path = require('path');

module.exports = {
  entry:{
    'index':'./index.js'
  },
  output:{
    path: path.resolve(__dirname,'./output'),
    filename:'[name].output.js',
    pathinfo:true
  },
  plugins:[
    new webpack.DllReferencePlugin({
      context: __dirname,
      manifest: require( './output/common-manifest.json' )
    })
  ]
};

Let's see the output of dll common.dll.js:

Important! the libFn has been renamed to exports["a"]
/* harmony export */ exports["a"] = libFn;function libFn(){

/************************************************************************/
/******/ ([
/* 0 */
/*!*******************!*\
  !*** ./common.js ***!
  \*******************/
/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__lib__ = __webpack_require__(/*! ./lib */ 1);
/* harmony export */ exports["commonFn"] = commonFn;

function commonFn(){
  __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__lib__["a" /* libFn */])()
}

/***/ },
/* 1 */
/*!****************!*\
  !*** ./lib.js ***!
  \****************/
/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony export */ exports["a"] = libFn;function libFn(){
  return 'libFn'
}

/***/ },
/* 2 */
/*!******************!*\
  !*** dll common ***!
  \******************/
/***/ function(module, exports, __webpack_require__) {

module.exports = __webpack_require__;

/***/ }
/******/ ]);

the output of entry index.output.js:

Still use __WEBPACK_IMPORTED_MODULE_0__lib__["libFn"])() to visit it.

/************************************************************************/
/******/ ([
/* 0 */
/*!****************************************************!*\
  !*** delegated ./lib.js from dll-reference common ***!
  \****************************************************/
/***/ function(module, exports, __webpack_require__) {

module.exports = (__webpack_require__(1))(1);

/***/ },
/* 1 */
/*!*************************!*\
  !*** external "common" ***!
  \*************************/
/***/ function(module, exports) {

module.exports = common;

/***/ },
/* 2 */
/*!******************!*\
  !*** ./index.js ***!
  \******************/
/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__lib__ = __webpack_require__(/*! ./lib */ 0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__lib___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__lib__);


console.log( 'index', __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__lib__["libFn"])() )

/***/ }
/******/ ]);
  • What is the expected behavior?
    Import the libFn() to index.js from the lib.js module ( which was included with dll bundle ) by correct name.
  • What is the motivation / use case for changing the behavior?
  • Browser: all
  • Language: ES6/7

All demo codes can be see at: https://gist.github.com/mc-zone/1232ae480c2f782cbd403ced85c87aa9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions