Dynamic requires are not currently supported by rollup-plugin-commonjs
Closed this issue · 7 comments
When I use Rollup (https://rollupjs.org/) to bundle Winston, the following error is thrown when running the app:
node example/index.js
/Users/mike/logging/lib/bundle.js:21
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
^
Error: Dynamic requires are not currently supported by rollup-plugin-commonjs
at commonjsRequire (/Users/mike/logging/lib/bundle.js:21:8)
at Function.get (/Users/mike/logging/lib/bundle.js:8108:31)
at _getConsoleLogFormat (/Users/mike/logging/lib/bundle.js:10777:10)
at _winstonConsole (/Users/mike/logging/lib/bundle.js:10792:13)
at getTransports (/Users/mike/logging/lib/bundle.js:10814:13)
at Object._init (/Users/mike/logging/lib/bundle.js:10820:17)
at Object.<anonymous> (/Users/mike/logging/example/index.js:4:23)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
The issue is caused by https://github.com/winstonjs/logform/blob/master/index.js#L27. Ideally, it'd be great to revert back to 972dbec#diff-168726dbe96b3ce427e7fedce31bb0bcL21. Although more verbose, it would open up Winston to being bundled by Rollup once winstonjs/winston#1100 is merged.
This is also a major issue when trying to integrate with https://github.com/zeit/pkg.
I'm still getting this error
Error: Dynamic requires are not currently supported by rollup-plugin-commonjs
tracked down to logform.
Has this been fixed or pushed?
Fix has been pushed. I am unsure of what rollup considers a "dynamic require" this is not dynamic, but it does use Object.defineProperty
:https://github.com/winstonjs/logform/blob/master/browser.js#L18-L35
Please reopen this issue. I have a minimal reproduction here:
https://github.com/westonpace/winston-rollup-test
To reproduce:
git clone https://github.com/westonpace/winston-rollup-test
cd winston-rollup-test
npm install
npm run build
node bundle.cjs.js
The issue in question is this line:
Line 28 in 834f7c9
I don't use rollup, but I think you need to actually use the https://github.com/rollup/rollup-plugin-node-resolve package you're importing in your rollup config, and specify browser: true
per the Usage in https://github.com/rollup/rollup-plugin-node-resolve
. Then you should get the browser version of things which don't have the dynamic requires. Lmk if that doesn't work for you.
Yes, that works. I hadn't thought to look for it since I am not running in the browser.
This issue also causes a slew of warnings (that then become runtime issues I have to assume, looking at the output files) with evanw/esbuild. It looks like my best workaround for the time being is to fork this repo and use https://classic.yarnpkg.com/en/docs/selective-version-resolutions/ to point at that fork?