首页 > 解决方案 > 反应:找不到模块:无法解析“xmlhttprequest”

问题描述

尝试构建我的 React 项目时出现错误:

./node_modules/ethers/utils/web.js Module not found: Can't resolve 'xmlhttprequest' in '/mnt/c/Users/.../node_modules/ethers/utils'

在 package.json 中: "dependencies": { "@material-ui/core": "^3.8.1", "@material-ui/icons": "^3.0.1", "axios": "^0.18.0", "immutability-helper": "^2.9.0", "moment": "^2.22.2", "react": "^16.7.0", "react-dom": "^16.7.0", "react-router-dom": "^4.3.1", "react-scripts": "^2.1.2" },

我应该怎么办?

标签: reactjsnpmwebpackxmlhttprequesttruffle

解决方案


要解决此问题,您需要安装不同版本的 ethers,如本期所述:

https://github.com/trufflesuite/truffle/issues/1614#issuecomment-452158490

与解决方案的确切评论:

ethers (v4.0.0-beta.1) 被安装为 web3-eth-abi (v1.0.0-beta.37) 的依赖项,这导致 xmlhttprequest 投诉并且基本上使 truffle-contract 无法使用。我现在可以通过手动将以太币升级到 v4.0.20 来解决它。

$ npm install ethers@4.0.20


推荐阅读