Closed
Description
- Rollup Plugin Name: commonjs
- Rollup Plugin Version: 11.1.0
- Rollup Version: 2.7.3
- Operating System (or Browser): Windows 10
- Node Version: 13.9.0
How Do We Reproduce?
Repro repo at https://github.com/SupernaviX/rollup-plugin-commonjs-broken-isomorphic-require
Bundle a module which checks if require
is defined, and requires a module if it is.
Expected Behavior
Since the require statement will never be called in the browser, it should ideally be transpiled out. Since the original code worked in the browser, the new code should work too.
Actual Behavior
The require statement is converted into a static import. Even though the module is never actually used, it becomes a hard dependency and the file no longer works in the browser.
Relevant snippet of code:
// Add isomorphic support for TextDecoder
let TextDecoder = undefined;
if (typeof window === "object") {
TextDecoder = window.TextDecoder;
} else if (typeof self === "object") {
TextDecoder = self.TextDecoder;
} else if (typeof require === "function") {
TextDecoder = require("util").TextDecoder;
}
This might be a duplicate of #342, I'm not sure.