-
Notifications
You must be signed in to change notification settings - Fork 779
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
Module not found: Error: Can't resolve 'crypto' #2873
Comments
Interesting. I take it you're using webpack for the first issue (or both)? What does your webpack config look like? |
@straker As far as I can tell, we recently added https://github.com/ember-a11y/ember-a11y-testing to our stack (this is an ember app). We do not use webpack directly, it's included via https://github.com/ef4/ember-auto-import. I think that warning is probably safe to ignore, but the other one is puzzling. |
"Deoptimized styling" is not the fault of axe-core, we can address that in the babel settings. The other warning about crypto though would be good to fix here. One way would be to split the node-specific parts of the implementation into a separate file so that browsers can use only the part that doesn't refer to any node-isms. |
I addressed the "deoptimized styling" warning for anyone consuming axe-core (or anything else that ships a file bigger than 500kb) via ember-auto-import in embroider-build/ember-auto-import#386 |
As of axe-core 4.1.3, axe-core attempts to use The problem we found using Webpack was that it would swap in crypto-browserify. That is completely unnecessary, and will throw if you try to use it in JSDOM. The fix we found was to set Bundlers do all sorts of odd and unpredictable things. It's not something we can really code against. My guess is your problem comes from the same source; axe-core gets too big because webpack pulls in |
While I relate 100% and have shared this pain, standards for solving this particular problem have improved immensely recently. Stable node has support for conditional exports and the popular bundlers have all fallen into line by following that spec. It lets you swap out the implementation of a file based on the conditions in which it will be used (node vs browser being the most relevant here). The root problem here is that |
My comment above should solve this issue. We'll keep an eye on this. I suspect there are only a hand full of projects that need to bundle axe-core, and it'll be more efficient for each of them to work out the best solve for their repo, then it is for us to maintain a comprehensive list of bundlers and plugins for bundlers and how to bundle axe-core in it. If this turns out to be a more frequent issue than I expect, we'll revisit. |
The whole point of Node standardizing conditional exports is so you don't need to maintain anything bundler-specific. |
You're right, and axe-core may very well adopt conditional exports at some point. Conditional exports doesn't actually solve the problem though. We'd need to create two variations of axe-core, one that has the |
@WilcoFiers lets get rid of the dependency on |
#4155) #### Details This PR updates `axe-core` to the recently-released v4.2.0. The bulk of the code changes here are an implementation of a custom `axe.frameMessenger` based on `browser.runtime.sendMessage` (`axe-frame-messenger.ts`), which allows us to avoid issues with target pages that intercept `window.postMessage` messages. Other notable changes include: * `test-status-choice-group.ts`: moved an `aria-label` which was violating a new `aria-allowed-attrs` rule variant (ARIA 1.2 disallows this attribute on `<span>` elements. Verified this change visually and under NVDA (the component is used both for radio buttons within assisted assessment instance tables and for the initial "pass/fail" radio buttons in manual requirements). * `webpack.config.js` required a change to work around dequelabs/axe-core#2873 * `get-rule-inclusions.test.ts.snap` enumerates the rule delta with the new version (@iamrafan is putting together fuller change notes that we'll be including with release notes when we release this) ##### Motivation See 1810733 ##### Context There are a few comments/typing workarounds in `axe-frame-messenger.ts` due to dequelabs/axe-core#2885 not quite making it in time for 4.2.0; we'll need to update to account for that when we pick up [email protected] #### Pull request checklist <!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox --> - [x] Addresses an existing issue: 1810733 - [x] Ran `yarn fastpass` - [x] Added/updated relevant unit test(s) (and ran `yarn test`) - [x] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage` - [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See `CONTRIBUTING.md`. - [n/a] (UI changes only) Added screenshots/GIFs to description above - [x] (UI changes only) Verified usability with NVDA/JAWS #### Co-authors Co-authored-by: JGibson2019 <[email protected]> Co-authored-by: lisli1 <[email protected]> Co-authored-by: Madalyn <[email protected]>
I tried the I'm using cypress-axe |
Hello, I see this issue after upgrading to Create React App 5, which uses Webpack 5 (instead of Webpack 4). It seems Webpack 4 was automagically using a crypto polyfill. "@axe-core/react": "^4.3.2", Here's the messages it gives: WARNING in ./node_modules/@axe-core/react/node_modules/axe-core/axe.js 6752:25-42
Module not found: Error: Can't resolve 'crypto' in '/home/rene/dev/headlamp/frontend/node_modules/@axe-core/react/node_modules/axe-core'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/@axe-core/react/dist/index.js 19:14-33
@ ./src/index.tsx 16:14-40 |
Thanks for bringing this up. This continues to come up. I'm going to see if we can take it out safely. It shouldn't be necessary. |
Hi, I've had the same issue. Would you please suggest a workaround? |
We have removed crypto and it should be released next week with axe-core v4.4. |
Discovered #2840 along with two other warnings.
Upgraded to 4.1.4 and the issue referenced in that PR went away, but two remain (one of which seems related).
Product: axe-core
Expectation: build without warnings
Actual:
Looks like two warnings.
Might be a non-issue.
I attempted setting
In package.json based on some related issues in other libs.
Motivation: no warnings
The text was updated successfully, but these errors were encountered: