Skip to content

commonjs: did not wrap minimized webpack output lib as format commonjs2  #935

@githoniel

Description

@githoniel

Expected Behavior

webpack-commonjs2.min.js is minimize of webpack-commonjs2.js in the reproduction repo. so they should both be wrapped by getDefaultExportFromCjs

Actual Behavior

webpack-commonjs2.min.js is not wrap by getDefaultExportFromCjs and will throw error VM214:122 Uncaught TypeError: webpackCommonjs2_min is not a constructor when execute

Additional Information

webpackBootstrap in lib: commonjs2 is below

/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};

after minimization it will be

r.r = function (e) {
    "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
      value: "Module"
    }), Object.defineProperty(e, "__esModule", {
      value: !0
    })
  }

the problem is Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); will get true before minimization but false after minimization in

export function isDefineCompiledEsm(node) {
const definedProperty =
getDefinePropertyCallName(node, 'exports') || getDefinePropertyCallName(node, 'module.exports');
if (definedProperty && definedProperty.key === KEY_COMPILED_ESM) {
return isTruthy(definedProperty.value);
}
return false;
}

when transformCommonjs because of target is rename from exports to e

maybe we should revert #537 or just loose it by to not check targetName === 'module'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions