【发布时间】:2022-08-20 04:35:41
【问题描述】:
我是 Web3 的新手,我正在尝试创建一个与 web3 集成的反应应用程序。以下是我在 Ubuntu 中遵循的步骤。
create-react-app app_name
cd app_name
npm i --save web3
npm start
一切正常,我得到了反应应用主页。
现在,只要我将以下代码行放入 App.js 中,应用程序就会中断,并且出现以下长错误。 (见下文,第 5 行)
import Web3 from \"web3\";
我得到的错误如下。
Compiled with problems:X
ERROR in ./node_modules/cipher-base/index.js 3:16-43
Module not found: Error: Can\'t resolve \'stream\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/cipher-base\'
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: { \"stream\": require.resolve(\"stream-browserify\") }\'
- install \'stream-browserify\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"stream\": false }
ERROR in ./node_modules/eth-lib/lib/bytes.js 9:193-227
Module not found: Error: Can\'t resolve \'crypto\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/eth-lib/lib\'
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 }
ERROR in ./node_modules/ethereumjs-util/dist.browser/account.js 71:31-48
Module not found: Error: Can\'t resolve \'assert\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/ethereumjs-util/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: { \"assert\": require.resolve(\"assert/\") }\'
- install \'assert\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"assert\": false }
ERROR in ./node_modules/ethereumjs-util/dist.browser/address.js 14:31-48
Module not found: Error: Can\'t resolve \'assert\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/ethereumjs-util/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: { \"assert\": require.resolve(\"assert/\") }\'
- install \'assert\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"assert\": false }
ERROR in ./node_modules/ethereumjs-util/dist.browser/object.js 46:31-48
Module not found: Error: Can\'t resolve \'assert\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/ethereumjs-util/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: { \"assert\": require.resolve(\"assert/\") }\'
- install \'assert\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"assert\": false }
ERROR in ./node_modules/web3-eth-accounts/lib/index.js 31:74-91
Module not found: Error: Can\'t resolve \'crypto\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/web3-eth-accounts/lib\'
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 }
ERROR in ./node_modules/web3-eth-accounts/node_modules/eth-lib/lib/bytes.js 7:193-227
Module not found: Error: Can\'t resolve \'crypto\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/web3-eth-accounts/node_modules/eth-lib/lib\'
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 }
ERROR in ./node_modules/web3-providers-http/lib/index.js 30:11-26
Module not found: Error: Can\'t resolve \'http\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/web3-providers-http/lib\'
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: { \"http\": require.resolve(\"stream-http\") }\'
- install \'stream-http\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"http\": false }
ERROR in ./node_modules/web3-providers-http/lib/index.js 32:12-28
Module not found: Error: Can\'t resolve \'https\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/web3-providers-http/lib\'
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: { \"https\": require.resolve(\"https-browserify\") }\'
- install \'https-browserify\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"https\": false }
ERROR in ./node_modules/web3-providers-ws/lib/helpers.js 11:12-26
Module not found: Error: Can\'t resolve \'url\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/web3-providers-ws/lib\'
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: { \"url\": require.resolve(\"url/\") }\'
- install \'url\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"url\": false }
ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js 37:11-26
Module not found: Error: Can\'t resolve \'http\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/xhr2-cookies/dist\'
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: { \"http\": require.resolve(\"stream-http\") }\'
- install \'stream-http\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"http\": false }
ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js 39:12-28
Module not found: Error: Can\'t resolve \'https\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/xhr2-cookies/dist\'
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: { \"https\": require.resolve(\"https-browserify\") }\'
- install \'https-browserify\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"https\": false }
ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js 41:9-22
Module not found: Error: Can\'t resolve \'os\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/xhr2-cookies/dist\'
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: { \"os\": require.resolve(\"os-browserify/browser\") }\'
- install \'os-browserify\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"os\": false }
ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js 43:10-24
Module not found: Error: Can\'t resolve \'url\' in \'/home/gkv/Stuff/Tutorial/Projects/react/lottery-react-new/node_modules/xhr2-cookies/dist\'
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: { \"url\": require.resolve(\"url/\") }\'
- install \'url\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"url\": false }
我尝试了多个stackoverflow帖子,但似乎都没有适当的解决方案。
- Error Library web3 and Webpack in react and angular [closed]
- Module not found: Error: Can\'t resolve \'stream\' in \'C:\\dev\\jszip-test\\node_modules\\jszip\\lib\'
- I am getting this error whilr importing Web3 from web3 in react js 17.0.1.how to fix this
如果有人可以提供帮助,那就太好了。我已经为此苦苦挣扎了 5 天。
-
你能显示你的 package.json 文件吗?
-
错误消息实际上是在告诉您它有什么问题。您没有给定软件包的 polyfill。
标签: reactjs webpack create-react-app web3js