question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken crypto dependency in webpack 5

See original GitHub issue

I’m using use-shopping-cart in a gatsby project. The current version of gatsby (3.0) uses webpack 5. Webpack 5 fails on build with use-shopping-cart due to the crypto dependency (error msg below). It looks like crypto is deprecated: crypto on npm. I get the error with both the current stable version of use-shopping-cart on npm (2.4.3) and the latest verstion (3.0.0-beta3). Any suggestions?

Can't resolve 'crypto' in '[PROJECT_DIR]/node_modules/use-shopping-cart/dist'

If you're trying to use a package make sure that 'crypto' is installed. If you're trying to use a local
file make sure that the path is correct.

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 }

File: node_modules/use-shopping-cart/dist/index.es.js:19:0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
andria-devcommented, Mar 28, 2021

If Webpack 5 used in Gatsby 3 still complains after we publish the uuid and rollup alias changes — which we haven’t yet — then I would say that the following two links will probably solve your problem.

Polyfilling Node’s Core APIs

https://github.com/Richienb/node-polyfill-webpack-plugin

The node-polyfill-webpack-plugin package was specifically introduced to polyfill the Node APIs — i.e crypto — that Webpack 5 stopped polyfilling by default.

Adding a Custom Webpack Config to Gatsby

https://www.gatsbyjs.com/docs/how-to/custom-configuration/add-custom-webpack-config/

Well, now you know how to polyfill the right things but how do you do that in a Gatsby 3 project? In the gatsby-node.js file, you should be able to do the following.

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({ plugins: [new NodePolyfillPlugin()] })
}

If this does not work for you, please let us know.

1reaction
felipesousacommented, Apr 4, 2021

thanks a lot @ChrisBrownie55!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React v18 crypto module not found Breaking Change
My react application was working fine a couple of hours ago, and now this error keeps appearing, even when I make another react...
Read more >
Can't resolve 'crypto' - updating webpack to v.5 · Issue #614
Hello, To people like me that updated a project to webpack 5 and dropbox 9 and got this error: ERROR in .
Read more >
Module not found: Error: Can't resolve 'crypto' [Solved]
The error "Module not found: Error: Can't resolve 'crypto'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >
Webpack 5 errors | ImmutableX Documentation
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core ... The following missing dependencies will have to be installed: crypto-browserify, ......
Read more >
To v5 from v4 - webpack
Upgrade webpack 4 and its plugins/loaders · Make sure your build has no errors or warnings · Make sure to use mode ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found