Bug report
Ccommonjs modules stop whole project tree shaking!
What is the current behavior?
The babelrc:
["@babel/preset-env", {
"modules": false,
"targets": {
"browsers": ["> 1%%", "ie > 9"]
},
"useBuiltIns": "usage"
}]
When i use bebel-preset-env with webpack4, require or import
a commonjs module(now many module have no esm)
// a.js
module.exports = {};
// b.js
const a = require('./a'); // or import a from './a';
it throw the errors in the browser:
Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
When i set the "modules": "commonjs"
, no error. but becaulse babel transform all the es6 module to commonjs, can get the tree shakings
.
If the current behavior is a bug, please provide the steps to reproduce.
module.exports
is read-only when module: false
, but is writable when "modules": "commonjs"
.
If this is right, so can’t use any other module types in the project when i want use tree shaking
?
What is the expected behavior?
Can use tree shaking
with commonjs modules
.
maybe need to change the module.exports
in harmony-module.js
towritable
?
Object.defineProperty(module, "exports", {
enumerable: true,
writable: true
});
Other relevant information:
webpack version: 4.17.1
Node.js version: 8.9
Operating System: macos
Additional tools: bebel-preset-env, bebel7
same problem
errors in the browser:
Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
dist/app.js
webpack version: 4.17.1
Additional tools: bebel-preset-env, bebel7
I have the same problem: