Webpack 5不再对节点核心模块进行自动填充。 请问怎么修?
break CHANGE:默认情况下,webpack < 5用于为node.js核心模块包含polyfills。 现在情况已经不同了。验证你是否需要这个模块,并为它配置一个填充。
Webpack 5不再对节点核心模块进行自动填充。 请问怎么修?
break CHANGE:默认情况下,webpack < 5用于为node.js核心模块包含polyfills。 现在情况已经不同了。验证你是否需要这个模块,并为它配置一个填充。
当前回答
我的问题是,我试图使用JSON。解析,然后当我开始写,自动完成显示我json(注意小字母),尽管我重命名为json。当我按回车键时,它自动导入 (import {json} from "express/lib/response";) 这是原因,我根本没有注意到,在后来的开发过程中,我的应用程序非常糟糕,我花了大约6个小时才注意到这一点,因为应用程序相当大。
所以如果上面的解决方案都不起作用,看看你是否没有导入一些东西。
其他回答
在create-react-app v17和脚本5.0.0中,你需要在webpack.config.js中添加一个备份,并安装'process'。
`module.exports = function (webpackEnv) {
.........
return {
.........
resolve: {
..........
fallback: { "process": require.resolve("process/browser") },`
npm install assert --save
npm install buffer --save
对于任何面临类似问题的人,只需安装缺少的模块。这些模块被报告为缺失,因为它们是node.js的一部分,但也可以通过npm单独使用。
Secret的答案几乎对我有用(我还没有足够的声誉来评论,抱歉!)
按照他们的回答,然后告诉我,因为在eslint的要求版本的差异,我应该添加SKIP_PREFLIGHT_CHECK=true到项目中的.env文件,所以我只是把它添加到我现有的一个。
然后它将成功构建(终于!)但后来我注意到,至少在Chrome中,我无法点击任何东西,甚至无法选择任何文本。事实证明,在检查器中仍然有一个Iframe在所有可以删除的东西之上。-这适用于运行一个开发版本,npm run start,我不确定它是否适用于生产版本。
我必须说,在我看来,这种突然的变化真的没有经过很好的考虑!
我的VUE解决方案
const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack');
module.exports = defineConfig({
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
})
],
resolve: {
fallback: {
"os": require.resolve("os-browserify/browser"),
"url": require.resolve("url/"),
"crypto": require.resolve("crypto-browserify"),
"https": require.resolve("https-browserify"),
"http": require.resolve("stream-http"),
"assert": require.resolve("assert/"),
"stream": require.resolve("stream-browserify"),
"buffer": require.resolve("buffer")
}
}
},
transpileDependencies: [
'vuetify'
]
})
Compiled with problems:X
ERROR in ./node_modules/body-parser/lib/read.js 24:11-26
Module not found: Error: Can't resolve 'zlib' in 'E:\My Documents\work\web\mbamasala\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/body-parser/lib/types/urlencoded.js 217:12-34
Module not found: Error: Can't resolve 'querystring' in 'E:\My Documents\work\web\mbamasala\node_modules\body-parser\lib\types'
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: { "querystring": require.resolve("querystring-es3") }'
- install 'querystring-es3'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "querystring": false }
ERROR in ./node_modules/destroy/index.js 15:17-41
Module not found: Error: Can't resolve 'fs' in 'E:\My Documents\work\web\mbamasala\node_modules\destroy'
ERROR in ./node_modules/destroy/index.js 17:13-30
Module not found: Error: Can't resolve 'stream' in 'E:\My Documents\work\web\mbamasala\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 }
ERROR in ./node_modules/destroy/index.js 19:11-26
Module not found: Error: Can't resolve 'zlib' in 'E:\My Documents\work\web\mbamasala\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/mime-types/index.js 15:14-37
Module not found: Error: Can't resolve 'path' in 'E:\My Documents\work\web\mbamasala\node_modules\mime-types'
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 }
ERROR in ./node_modules/safer-buffer/safer.js 4:13-30
Module not found: Error: Can't resolve 'buffer' in 'E:\My Documents\work\web\mbamasala\node_modules\safer-buffer'
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: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/string_decoder/node_modules/safe-buffer/index.js 4:13-30
Module not found: Error: Can't resolve 'buffer' in 'E:\My Documents\work\web\mbamasala\node_modules\string_decoder\node_modules\safe-buffer'
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: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
我试了很多办法,但都没有解决。 在手动搜索后,我得到了一行代码,它自动插入到我的vs code中 从body-parser导入{json} 我移开了,节省了时间。 我希望它能帮助到一些人。 谢谢。