我正在通过 HTML、hardhat、web3js 和 ether.js 构建分布式应用程序,但在为浏览器环境捆绑我的项目时遇到了一致的问题。
可能还值得注意的是,在不同的时候,我安装的一些模块没有反映在我的 node_module 中,我不得不下载模块文件并将其添加到 node_modules 以使一些依赖项工作。我在使用 webpack5 时遇到了 polyfill 错误,所以我降级到 webpack4,webpack4 的 node_modules 有一些问题所以我决定使用 browserify。我已经阅读了 3 个星期的 webpack 文档,chatgpt 协助直到死胡同,它说我应该联系包管理器寻求帮助。
当我运行命令时
browserify ./frontend/main.js > ./dist/bundle.js
我得到这个错误代码
Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\Users\HP\Downloads\wallet5\fs'
required by C:\Users\HP\Downloads\wallet5\node_modules\hardhat\internal\artifacts.js
我在节点模块中安装了 fs,它在 packagejson 文件中,我可以在 node_modules 中看到它。
这是我遇到的最新此类错误。我删除了 node_modules 并运行
npm install
这对我没有帮助。
我的node版本是v18.15.0
这是我的 package.json 文件
{
"name": "wallet5",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "browserify ./frontend/main.js > ./dist/bundle.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"babelify": "^8.0.0",
"browserify": "^17.0.0",
"browserify-fs": "^1.0.0",
"dotenv": "^16.0.3",
"ethers": "^5.0.0",
"fs": "^0.0.1-security",
"solc": "^0.8.19",
"testpackage0110": "^1.0.3",
"watchify": "^4.0.0",
"web3": "^1.9.0"
},
"devDependencies": {
"@babel/core": "^7.21.4",
"@babel/preset-env": "^7.21.4",
"hardhat": "^2.13.0"
}
}