core js modules insertion breaks AMD exports
See original GitHub issueI’m submitting a bug report
Webpack Version: 4.16.0
Babel Core Version: 7.0.0-rc.1
Babel Loader Version: 8.0.0-beta.4
Please tell us about your environment: macOS 10.13.6, node v8.9.4, npm 6.3.0
Current behavior:
When babel
found a method that probably need a polyfill it is inserting
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var core_js_modules_es6_regexp_replace__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core-js/modules/es6.regexp.replace */ "../node_modules/core-js/modules/es6.regexp.replace.js");
/* harmony import */ var core_js_modules_es6_regexp_replace__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es6_regexp_replace__WEBPACK_IMPORTED_MODULE_0__);
define(function (require, exports) {
function getUppercase(featureName) {
return featureName.replace(/-/g, '_');
}
exports.foo = function () {
getUppercase();
};
exports.QUX = 'QUX';
});
/***/ }),
That is probably correct. But AMD code that follows it stops exporting it members.
Removing modules: false
from .babelrc
seems fix this issue, but is not desired, because of tree-shaking.
Console shows warnings:
WARNING in ./js/index.js 2:4-7
"export 'QUX' (imported as 'BAZ') was not found in './test'
@ multi ./js/index.js
WARNING in ./js/index.js 2:0-3
"export 'foo' (imported as 'bar') was not found in './test'
@ multi ./js/index.js
Expected/desired behavior: Without polyfills inserting, module exported correctly
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports) {
function getUppercase(featureName) {// return featureName.replace(/-/g, '_');
}
exports.foo = function () {
getUppercase();
};
exports.QUX = 'QUX';
}).call(exports, __webpack_require__, exports, module),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
/***/ }),
- 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.
{
"presets": [
["@babel/preset-env", {
"modules": false,
"useBuiltIns": "usage"
}],
"@babel/preset-react"
]
}
define(function(require, exports) {
function getUppercase(featureName) {
return featureName.replace(/-/g, '_');
}
exports.foo = function() {
getUppercase();
};
exports.QUX = 'QUX';
});
-
What is the expected behavior? Module exports it members regardless of polyfills inserting
-
What is the motivation / use case for changing the behavior? Using webpack with multiple legacy modules
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Oh right, for that you need to set
sourceType: "unambiguous"
so that Babel doesn’t just assume the file is an ES module.Looks like
sourceType
fix AMD build