Closed michalvadak closed 2 years ago
So unfortunately it's pretty common in React bundles to see something like the following:
if (process.env.NODE_ENV === 'production') {
module.exports = require('./redux-toolkit.cjs.production.min.js')
} else {
module.exports = require('./redux-toolkit.cjs.development.js')
}
(see #824)
This results in the process is not defined
error when used in the browser as process
is specific to Node.
You can use Microbundle's --define
flag to correct this though.
microbundle .... --define process.env.NODE_ENV=production
You should notice that this will also cut your build output roughly in half, as Microbundle can now shake out the dev-only code.
@rschristian
Could you please help me with this also?
--strict
flag when compiling the UMD package. Do you think there is any major difference?The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
Sorry for the delay.
1) The major difference is strict mode. I'm not positive that the minification takes advantage of the lack of strict mode, but that could be a few bytes saved when not using it. Really it's just up to you and the behavior you want.
2) Are you using this
at the top level? It's from Rollup, and it's a pretty valid warning as there could be issues when generating older output (I think this goes away with es2017/Microbundle's modern).
See https://rollupjs.org/guide/en/#error-this-is-undefined, https://github.com/rollup/rollup/issues/1518, and https://github.com/developit/microbundle/issues/682
Closing out, seems to be resolved.
I tried to export my React package as UMD package to be able to include it in HTML. But I can't get it to work. I can't access it.
This is my index.tsx
This is my command in
package.json
microbundle -o umd --no-compress --format umd --name MyModule --jsx React.createElement --external none
This is my code in HTML
And I get this error