CommonJS plugin strictRequires
settings always hoists NodeJS conditional require
calls from an imported UMD file
#1381
Unanswered
Bloodsucker
asked this question in
Q&A
Replies: 1 comment
-
For anyone interested, the workaround I've is to replace |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
Given a entry-point
index.js
:And a UMD bundle (
umd.cjs
) with "dynamic" require calls to NodeJS builtins that are called only under certain conditions:A rollup config
rollup.config.js
:This results in the following final UMD bundle file:
The
umd.cjs
requirerequire('os');
has been replaced with areturn require$$0;
which changes the logic that is happening inside the bundle. This also causes the following errors:I believe this is somehow expected. However, if I use the setting
strictRequires
from the plugin@rollup/plugin-commonjs
in the rollup.config.js:The expectation was to NOT hoist the require('os') call in the resulting final UMD file. In other words. From:
to something like (modified manually):
Paradoxically, an imported ES6 module file with dynamic require doesn't result in a hoisted require call.
Does anybody know how to avoid the hoisting of the file and how to fix the bundling errors?
Beta Was this translation helpful? Give feedback.
All reactions