kentcdodds / babel-plugin-macros

🎣 Allows you to build simple compile-time libraries
https://npm.im/babel-plugin-macros
MIT License
2.62k stars 135 forks source link

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted #187

Closed rishu605 closed 1 year ago

rishu605 commented 1 year ago

I have been setting up swc with webpack. There is a package I use for linting -- eslint-config-react-app. This has a dependency on babel-plugin-macros. I get the following warning on starting the dev server.

Webpack version is 5.75 WARNING in ./node_modules/babel-plugin-macros/dist/index.js 75:22-29 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted Looks like it is caused due to the way require is being used in this plugin. Not sure how to get rid of this warning.

I removed all dependencies of babel and it's related packages to avoid any potential conflicts between swc and babel but the warning is still present.

conartist6 commented 1 year ago

It's most likely the way babel-plugin-macros loads cosmiconfig...

conartist6 commented 1 year ago

https://github.com/kentcdodds/babel-plugin-macros/blob/8fc6383ef04f628d0b799a9b281c5fc0693b25ac/src/index.js#L26-L27

rishu605 commented 1 year ago

The error message leads to this line in the code: Screenshot from 2022-12-11 22-15-21

conartist6 commented 1 year ago

Ah ok. So the warning is probably safe to ignore then right? Nothing is actually being required by this code, and the places that do call into this code probably all look like perfectly normal global.require('module-name') calls.

rishu605 commented 1 year ago

Looks like ignoring this warning won't cause any issues for now. Not sure though.

conartist6 commented 1 year ago

I'm pretty sure that ignoring it won't cause issues. The warning clearly seems to be about the ability to extract the dependency graph, which is not affected.

It does seem suspicious to me though that webpack would be parsing eslint-config-react-app. Why is a linter in the bundle?

rishu605 commented 1 year ago

Is there a way to prevent linting packages from being parsed while bundling through webpack!!

conartist6 commented 1 year ago

I don't know, because I don't know why it is parsing them.

GuYounes commented 1 year ago

Any news ?

conartist6 commented 1 year ago

No news, unless webpack offers some kind of special comment that silences that warning?