Web3 Issue : React Application not compiling(Web3问题:Reaction应用程序未编译)
问题描述
我在编译时遇到Reaction应用程序的问题。 请在下面找到问题和屏幕截图。
ERROR in ./node_modules/web3-providers-http/lib/index.js 30:11-26
Module not found: Error: Can't resolve 'http' in '/Users/rohit/Downloads/Personal/web3/react-minting-website/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 }
@ ./node_modules/web3-core-requestmanager/lib/index.js 56:16-46
@ ./node_modules/web3-core/lib/index.js 23:23-58
@ ./node_modules/web3/lib/index.js 32:11-31
@ ./src/index.js 10:0-24 14:13-17
仔细查看,我发现问题出在与Web3相关的依赖项上:
https://www.npmjs.com/package/web3
https://www.npmjs.com/package/@web3-react/core
https://www.npmjs.com/package/@web3-react/injected-connector
谁能帮我拿一下同样的东西?我正在使用LTS版本,这些版本的稳定版本是什么?
请提出建议。
推荐答案
随着webpack体型的增大,他们移除了网络包装5中的多层填充物。看起来您正在使用Create-Reaction-App(CRA),而webpack的配置在CRA中没有向用户公开。您可以使用eject公开它。您可能在Package.json:
"eject": "react-scripts eject"
因此运行npm run eject。不建议这样做,因为这意味着您将不再受益于CRA的更新。
您可以使用rewire或craco处理弹出。
拿到webpack配置后,您需要在webpack配置中添加resolve属性,并安装所有需要的包:
resolve: {
extensions: [".js", ".css"],
alias: {
// add as many aliases as you like!
// optional
components: path.resolve(__dirname, "src/components"),
},
fallback: {
// path: require.resolve("path-browserify"),
fs: false,
assert: require.resolve("assert/"),
os: require.resolve("os-browserify/browser"),
constants: require.resolve("constants-browserify"),
stream: require.resolve("stream-browserify"),
crypto: require.resolve("crypto-browserify"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
},
},
我有webpac5 Boilerplate。如果需要,您可以使用它:
由于多边形填充太多,您可以使用node-polyfill-webpack-plugin包,而不是手动全部安装。而不是
fallback属性const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); plugins: [ new HtmlWebpackPlugin({ title: "esBUild", template: "src/index.html", }), // instead of fallback new NodePolyfillPlugin(), new webpack.ProvidePlugin({ process: "process/browser", Buffer: ["buffer", "Buffer"], React: "react", }), ],
webpack5 boilerplate github repo
这篇关于Web3问题:Reaction应用程序未编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Web3问题:Reaction应用程序未编译
基础教程推荐
- CORS:当凭据标志为真时,无法在 Access-Control-Allow-Origin 中使用通配符 2022-01-01
- 在 Javascript 中使用 Fetch API 上传文件并显示进度 2022-01-01
- HTML5 画布调整为父级 2022-01-01
- 从快速中间件中排除路由 2022-01-01
- 最佳动态 JavaScript/JQuery 网格 2022-01-01
- 逻辑运算符 ||在 javascript 中,0 代表 Boolean false? 2022-01-01
- 使用 jQuery 在悬停时交换 DIV 类 2022-01-01
- 带角度的选项卡:仅使用 $http 在单击时加载选项卡 2022-01-01
- 即使每次插入第一个输入的值不同,第二个输入仍显示相同的输入值 2022-01-01
- 当木偶师打开Chrome时,不能使用Chrome扩展 2022-01-01
