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.

Webpack 5 Pollyfill Error in SDK

See original GitHub issue

Subject of the issue

I originally described the Issue in the Forum. I am now getting the same error working on another application, so I wanted to report it here to see if there may be a known fix for the bug.

Your environment

I am working in a react application where I am importing the algosdk and getting an error in node_modules/algosdk/dist/browser. Specifically, the error is coming from algosdk.min.js but when I searched in the file it is unreadable code. So, I am not sure what the file is or how to proceed.

Steps to reproduce

  1. cd react-app
  2. npm start

Expected behavior

Expected behavior is that the application functions as expected without the error. The application is functionally performing as expected on a local server. However, the error is obnoxiously reported by react and I would like to resolve the issue. I am not sure what is causing the problem because sometimes I get the error and sometimes I don’t. I tried changing the node_modules out to another node_modules from an application that was not producing the error, but it did not resolve the issue.

Actual behavior

ERROR in ./node_modules/algosdk/dist/browser/algosdk.min.js 7206:55-72
Module not found: Error: Can't resolve 'crypto' in '/Users/Programming/Game/node_modules/algosdk/dist/browser'

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 }

webpack compiled with 1 error and 66 warnings

Thanks in advance for advice or suggestions.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonpauloscommented, Sep 23, 2022

"crypto": require.resolve("crypto-browserify"),

Installing and using crypto-browserify will cause require("crypto") to resolve to require("crypto-browserify")

  resolve: {
    fallback: {
      crypto: false, // do not include a polyfill for crypto
    },

And setting the fallback to false will cause require("crypto") to resolve to false (or maybe null/undefined, I’m not too sure).

The difference is really whether you actually need a replacement for the crypto module or not. I expect both will work, but the simplest solution is the second.

1reaction
jasonpauloscommented, Sep 23, 2022

Unfortunately the Module not found: Error: Can't resolve 'crypto' error is because of one of our dependencies, tweetnacl-js.

I gave more context in this comment: https://github.com/algorand/js-algorand-sdk/issues/643#issuecomment-1241268534

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Polyfill node core modules in webpack 5
This was resolved simply by installing the buffer package with npm install -D buffer . 'fs'. Module not found: Error: Can't resolve 'fs ......
Read more >
How to polyfill node core modules in webpack 5 - Alchemy
The main issue with create-react-app and the polyfill error is that create-react-app, by default, hides the webpack config file inside the node- ...
Read more >
Webpack 5 Issues | Documentation - Web3Auth
This issue is caused due to the fact that the web3.js and ethers.js packages have certain dependencies, which are not present within the...
Read more >
BREAKING CHANGE: webpack < 5 used to include polyfills ...
You now receive an error while building an angular application regarding node polyfills and Webpack 5 https://i.stack.imgur.com/SpjFk.png.
Read more >
Webpack 5 Pollyfill Error - AlgoSDK - Algorand Forum
One problem is I can't find the path to: Desktop/Programming/Connect/node_modules/algosdk . This is strange because the algosdk should not be in ...
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