-
Notifications
You must be signed in to change notification settings - Fork 784
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
require function is used in a way in which dependencies cannot be statically extracted #2840
Comments
Thanks for the issue. I believe you'll want to open this in https://github.com/dequelabs/axe-core-npm (where |
Thank you so much for the fast response, @straker ! Here is an example of how we require @axe-core/react in the app: // a11y.js
import axeCore from '@axe-core/react';
export const axe = async (React, ReactDOM, { enabled = false, timeout = 5000, ...config }) => {
if (enabled) {
await axeCore(React, ReactDOM, timeout, config).catch(console.error);
}
}
// index.js
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>
document.getElementById(id),
);
axe(React, ReactDOM, {
enabled: !!process.env.MY_ENV_VAR,
}); The webpack configuration is pretty simple. We use babel-loader to transpile JSX to JS and DefinePlugin to use environment variables. That's pretty much it. |
I don't think this is an issue in the @axe-core/react library. I believe this was introduced with this line, added in the 4.1.3 release. I think what's happening here is Webpack parses the word "require", but doesn't understand that you're checking that the value is defined and not actually importing a dependency, so it throws the warning. I edited the line in my node_modules folder to drop the I have a PR incoming |
Fixes a warning thrown by Webpack for using "require" without importing anything. Warning reads "require function is used in a way in which dependencies cannot be statically extracted" Closes issue dequelabs#2840
Fixes a warning thrown by Webpack for using "require" without importing anything. Warning reads "require function is used in a way in which dependencies cannot be statically extracted" Closes issue #2840
This is now fixed in #2843. Will be available in the next release. |
Fixes a warning thrown by Webpack for using "require" without importing anything. Warning reads "require function is used in a way in which dependencies cannot be statically extracted" Closes issue #2840
I think I am seeing this in Steps I've taken
Add React Axe to Root Snippetif (process.env.NODE_ENV !== "production") {
import("@axe-core/react").then((axe) => {
axe.default(React, ReactDOM, 1000);
root.render(
<StrictMode>
<App />
</StrictMode>,
);
});
} else {
root.render(
<StrictMode>
<App />
</StrictMode>,
);
} Then I am seeing these errors in the console that ran Critical dependency warning in terminal
Axe does still seem to be providing accessibility warnings, so it is still working 👏 Reproduction Repo: https://github.com/brooksbecton/axe-core-react-warning-repro |
I am seeing the same issue as @brooksbecton using |
I am seeing the same issue as @brooksbecton and @damian-krupa using "react": "^17.0.0" with "axe-core": "^4.5.1". Webpack 5 throws this error during build. ./node_modules/axe-core/axe.js 379:46-53Critical dependency: require function is used in a way in which dependencies cannot be statically extracted |
Expectation:
As a consumer of the library I would like to understand why I am getting the warning (see below) at build time using webpack and what should I do to get rid of it.
Actual:
during a build process, I see the following warning
Misc:
The text was updated successfully, but these errors were encountered: