javascript - webpack < 5 默认情况下用于包含 Node.js 核心模块的 Polyfill。这已不再是这种情况

标签 javascript node.js reactjs webpack

我收到错误:

22 个错误有未显示的详细信息。 编译失败。 webpack < 5 默认情况下用于包含 Node.js 核心模块的 Polyfill。 这已不再是这种情况。验证您是否需要此模块并为其配置一个polyfill。

找不到模块:错误:无法解析“C:\Users\joshm\Downloads\New 文件夹 (14)\myapp\node_modules\body-parser\lib”中的“zlib” 重大更改:webpack < 5 默认情况下包含 Node.js 核心模块的 Polyfill。 这已不再是这种情况。验证您是否需要此模块并为其配置一个polyfill。

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 }
asset static/js/bundle.js 2.84 MiB [emitted] (name: main) 1 related asset
asset index.html 1.67 KiB [emitted]
asset asset-manifest.json 190 bytes [emitted]
cached modules 2.42 MiB (javascript) 28.3 KiB (runtime) [cached] 271 modules

WARNING in ./node_modules/express/lib/view.js 74:13-25
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/express/lib/application.js 26:11-28
 @ ./node_modules/express/lib/express.js 19:12-36
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

1 warning has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

ERROR in ./node_modules/body-parser/lib/read.js 20:11-26
Module not found: Error: Can't resolve 'zlib' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\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 }
 @ ./node_modules/body-parser/lib/types/json.js 21:11-29
 @ ./node_modules/body-parser/index.js 134:15-42
 @ ./node_modules/express/lib/express.js 13:17-39
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

ERROR in ./node_modules/content-disposition/index.js 19:15-39
Module not found: Error: Can't resolve 'path' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\node_modules\content-disposition'

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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }
 @ ./node_modules/express/lib/response.js 15:25-55
 @ ./node_modules/express/lib/express.js 27:10-31
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

ERROR in ./node_modules/cookie-signature/index.js 4:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\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 }
 @ ./node_modules/express/lib/response.js 35:11-43
 @ ./node_modules/express/lib/express.js 27:10-31
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

ERROR in ./node_modules/destroy/index.js 12:17-41
Module not found: Error: Can't resolve 'fs' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\node_modules\destroy'
 @ ./node_modules/send/index.js 19:14-32
 @ ./node_modules/express/lib/response.js 45:11-26
 @ ./node_modules/express/lib/express.js 27:10-31
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

ERROR in ./node_modules/destroy/index.js 14:13-30
Module not found: Error: Can't resolve 'stream' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\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: { "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 }
 @ ./node_modules/send/index.js 19:14-32
 @ ./node_modules/express/lib/response.js 45:11-26
 @ ./node_modules/express/lib/express.js 27:10-31
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

ERROR in ./node_modules/etag/index.js 18:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\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 }
 @ ./node_modules/express/lib/utils.js 25:11-26
 @ ./node_modules/express/lib/application.js 30:18-48 32:25-62 34:19-50
 @ ./node_modules/express/lib/express.js 19:12-36
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

ERROR in ./node_modules/etag/index.js 20:12-31
Module not found: Error: Can't resolve 'fs' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\node_modules\etag'
 @ ./node_modules/express/lib/utils.js 25:11-26
 @ ./node_modules/express/lib/application.js 30:18-48 32:25-62 34:19-50
 @ ./node_modules/express/lib/express.js 19:12-36
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36

ERROR in ./node_modules/express/lib/application.js 28:11-26
Module not found: Error: Can't resolve 'http' in 'C:\Users\joshm\Downloads\New folder (14)\myapp\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 }
 @ ./node_modules/express/lib/express.js 19:12-36
 @ ./node_modules/express/index.js 10:0-41
 @ ./src/Login.js 6:0-35 29:23-36
 @ ./src/App.js 8:0-28 39:38-43
 @ ./src/index.js 7:0-24 10:33-36



22 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.69.1 compiled with 22 errors and 1 warning in 2554 ms

webpack.config.js
module.exports = {
    
    resolve: {
        fallback: {
            "fs": false
        },
    }
}

最佳答案

我也有同样的问题。这个解决方案将帮助您:

  1. npm 我 Node -polyfill-webpack-plugin
  2. 将此代码写入vue.config.js

const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
  configureWebpack: {
    plugins: [new NodePolyfillPlugin()]
  }
};

关于javascript - webpack < 5 默认情况下用于包含 Node.js 核心模块的 Polyfill。这已不再是这种情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71315671/

相关文章:

javascript - 将按钮变成加载圆圈动画

javascript - Node.js 变量声明和范围

node.js - 缺少架构错误 : Schema hasn't been registered for model "Users"

javascript - React 功能组件中的 Prop 名称

javascript - React 路由器服务器端无法正常工作

css - 使用 Webpack 在 React 中构建 CSS 文件

javascript - typescript 动态访问对象键

javascript - 随机数生成器在 var 元素内部每次调用时都会给出相同的输出

node.js - 如何使用 nginx 禁用子域上的域代理重定向?

javascript - Node.js:通过迭代的 JSON POST 数据创建多个 MongoDB 文档