webpack 未找到模块:错误:无法解析“W:\React\掩体\node_modules\send”中的“fs”

8hhllhi2  于 2023-06-23  发布在  Webpack
关注(0)|答案(1)|浏览(122)

我对webpack有一个很大的问题。我有13个错误,我无法修复它们!
Log

Failed to compile.

Module not found: Error: Can't resolve 'zlib' in 'W:\React\bunker\node_modules\body-parser\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: { "zlib": require.resolve("browserify-zlib") }'    
        - install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "zlib": false }
WARNING in ./node_modules/express/lib/view.js 72:13-25
Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/on-finished/index.js 191:11-33
Module not found: Error: Can't resolve 'async_hooks' in 'W:\React\bunker\node_modules\on-finished'

WARNING in ./node_modules/raw-body/index.js 270:11-33
Module not found: Error: Can't resolve 'async_hooks' in 'W:\React\bunker\node_modules\raw-body'   

ERROR in ./node_modules/body-parser/lib/read.js 19:11-26
Module not found: Error: Can't resolve 'zlib' in 'W:\React\bunker\node_modules\body-parser\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: { "zlib": require.resolve("browserify-zlib") }'       
        - install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "zlib": false }

ERROR in ./node_modules/cookie-signature/index.js 5:13-30
Module not found: Error: Can't resolve 'crypto' in 'W:\React\bunker\node_modules\cookie-signature'

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/destroy/index.js 15:17-41
Module not found: Error: Can't resolve 'fs' in 'W:\React\bunker\node_modules\destroy'

ERROR in ./node_modules/destroy/index.js 17:11-26
Module not found: Error: Can't resolve 'zlib' in 'W:\React\bunker\node_modules\destroy'

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: { "zlib": require.resolve("browserify-zlib") }'
        - install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "zlib": false }

ERROR in ./node_modules/etag/index.js 20:13-30
Module not found: Error: Can't resolve 'crypto' in 'W:\React\bunker\node_modules\etag'

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/etag/index.js 21:12-31
Module not found: Error: Can't resolve 'fs' in 'W:\React\bunker\node_modules\etag'

ERROR in ./node_modules/express/lib/application.js 22:11-26
Module not found: Error: Can't resolve 'http' in 'W:\React\bunker\node_modules\express\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/express/lib/request.js 19:11-26
Module not found: Error: Can't resolve 'http' in 'W:\React\bunker\node_modules\express\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/express/lib/response.js 20:11-26
Module not found: Error: Can't resolve 'http' in 'W:\React\bunker\node_modules\express\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/express/lib/view.js 17:9-22
Module not found: Error: Can't resolve 'fs' in 'W:\React\bunker\node_modules\express\lib'

ERROR in ./node_modules/hot/hot.js 37:9-22
Module not found: Error: Can't resolve 'fs' in 'W:\React\bunker\node_modules\hot'

ERROR in ./node_modules/mime/mime.js 2:9-22
Module not found: Error: Can't resolve 'fs' in 'W:\React\bunker\node_modules\mime'

ERROR in ./node_modules/send/index.js 22:9-22
Module not found: Error: Can't resolve 'fs' in 'W:\React\bunker\node_modules\send'

webpack compiled with 13 errors and 3 warnings

我在webpack.config.js中有所有解析:
Webpack.config.js File
我有当前库的所有最新版本。我的项目目录中有英语名字。
你能帮我吗?
Package.json:

{
  "name": "my-webpack-project",
  "version": "1.0.0",
  "description": "My webpack project",
  "main": "index.js",
  "scripts": {
    "start": "react-scripts start",
    "build": "webpack --config webpack.config.js",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "prod_build": "webpack --mode production",
    "build:dev": "webpack --mode=development",
    "build:prod": "webpack --mode=production --node-env=production",
    "watch": "webpack --watch",
    "serve": "webpack serve"
  },
  "browser": {
    "fs": false
  },
  "author": "rjk3r",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.22.1",
    "@babel/preset-env": "^7.22.4",
    "@coreui/react": "^4.7.0",
    "@novu/node": "^0.13.0",
    "@react-pdf/renderer": "^3.1.11",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "async_hooks": "^1.0.0",
    "axios": "^1.3.4",
    "babel-polyfill": "^6.26.0",
    "bootstrap": "^5.2.3",
    "browserify-zlib": "^0.2.0",
    "crypto-browserify": "^3.12.0",
    "customize-cra": "^1.0.0",
    "dotenv": "^16.1.4",
    "express": "^4.18.2",
    "formik": "^2.2.9",
    "fs": "^0.0.1-security",
    "hot": "^0.0.7",
    "http-proxy-middleware": "^2.0.6",
    "husky": "^8.0.3",
    "knex": "^2.4.2",
    "less-loader": "^11.1.2",
    "marked": "^4.3.0",
    "mobx": "^6.9.0",
    "mobx-react": "^7.6.0",
    "net": "^1.0.2",
    "node-polyfill-webpack-plugin": "^2.0.1",
    "nodemon": "^2.0.22",
    "os-browserify": "^0.3.0",
    "pako": "^2.1.0",
    "path": "^0.12.7",
    "path-browserify": "^1.0.1",
    "pdfkit": "^0.13.0",
    "pg": "^8.10.0",
    "querystring": "^0.2.1",
    "react": "^18.2.0",
    "react-app-rewired": "^2.2.1",
    "react-bootstrap": "^2.7.2",
    "react-dom": "^18.2.0",
    "react-refresh-webpack-plugin": "^0.1.0",
    "react-router-dom": "^6.10.0",
    "react-scripts": "^5.0.1",
    "react-svg-loader": "^3.0.0",
    "react-validation": "^3.0.7",
    "request": "^2.88.2",
    "stream": "^0.0.2",
    "stream-http": "^3.2.0",
    "util": "^0.12.5",
    "validator": "^13.9.0",
    "web-vitals": "^2.1.0",
    "webpack": "^5.86.0",
    "yup": "^1.1.1"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/plugin-proposal-async-generator-functions": "^7.20.7",
    "@babel/preset-react": "^7.22.3",
    "@webpack-cli/generators": "^3.0.7",
    "autoprefixer": "^10.4.14",
    "babel-loader": "^9.1.2",
    "css-loader": "^6.8.1",
    "html-webpack-plugin": "^5.5.1",
    "mini-css-extract-plugin": "^2.7.5",
    "postcss": "^8.4.23",
    "postcss-loader": "^7.2.4",
    "prettier": "^2.8.7",
    "source-map-loader": "^4.0.1",
    "style-loader": "^3.3.3",
    "svg-url-loader": "^8.0.0",
    "webpack-dev-server": "^4.15.0",
    "workbox-webpack-plugin": "^6.5.4"
  }
}

如果你需要更多的信息,请在你的回答中写下这一点。
我试着更新webpack,包括所有polyfills,将项目目录更改为eng语言,尝试重新安装所有,尝试下载所有依赖项,使用“npm install”,总的来说我给予了。

ulydmbyx

ulydmbyx1#

要解决这些错误,您可以尝试以下步骤:

  • 安装缺少的模块:
  • 对于'zlib'模块,通过运行npm install browserify-zlib添加'browserify-zlib'包。
  • 对于'async_hooks'模块,运行npm install async_hooks
  • 配置webpack以包含node.js核心模块所需的polyfill:
  • 将以下后备配置添加到webpack.config.js文件中:
resolve: {
  fallback: {
    "zlib": require.resolve("browserify-zlib"),
    "crypto": require.resolve("crypto-browserify"),
    "http": require.resolve("stream-http"),
    "fs": false
  }
}
  • 安装所需的polyfill包:
  • 对于'crypto',运行npm install crypto-browserify
  • 对于'stream-http',运行npm install stream-http
  • 清理项目生成和依赖项缓存:
  • 删除“node_modules”文件夹。
  • 运行npm install以重新安装依赖项。

尝试以下操作并对结果进行注解,然后如果有任何错误,我们必须进行检查。

相关问题