Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic requires are not currently supported by rollup-plugin-commonjs #5

Closed
mikenikles opened this issue Oct 15, 2017 · 7 comments · Fixed by #18
Closed

Dynamic requires are not currently supported by rollup-plugin-commonjs #5

mikenikles opened this issue Oct 15, 2017 · 7 comments · Fixed by #18

Comments

@mikenikles
Copy link

mikenikles commented Oct 15, 2017

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.

@wyattjoh
Copy link

This is also a major issue when trying to integrate with https://github.com/zeit/pkg.

@JasonJJFS
Copy link

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?

@indexzero
Copy link
Member

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

@westonpace
Copy link

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:

return require(`./${path}.js`);

@DABH
Copy link
Contributor

DABH commented Feb 26, 2019

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.

@westonpace
Copy link

Yes, that works. I hadn't thought to look for it since I am not running in the browser.

@klardotsh
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants