Webpack 5不再对节点核心模块进行自动填充。 请问怎么修?
break CHANGE:默认情况下,webpack < 5用于为node.js核心模块包含polyfills。 现在情况已经不同了。验证你是否需要这个模块,并为它配置一个填充。
Webpack 5不再对节点核心模块进行自动填充。 请问怎么修?
break CHANGE:默认情况下,webpack < 5用于为node.js核心模块包含polyfills。 现在情况已经不同了。验证你是否需要这个模块,并为它配置一个填充。
当前回答
Create React App刚刚发布了v5,现在实现了Webpack v5。这将完全打破许多库,其中包括web3作为必需的节点核心库腻子将会丢失。
为了快速解决这个问题,你可以在package.json中修改这个:
"react-scripts": "^5.0.0"
这个
"react-scripts": "4.0.3"
在这之后:
rm -r node_modules
rm package-lock.json
npm install
其他回答
对我来说,我只是删除了一个未使用的导入,称为:
import res from "express/lib/response"
它把它修好了!
面对同样的问题,这里有一个解决方案:
删除package-lock。Json从项目文件夹和NPM卸载webpack 将react-script从5降级为4.0.3 确保包锁。Json被删除/删除 使用npm Install webpack@4.44.2安装webpack 最后,使用终端运行npm install
看起来你已经使用了默认情况下不包含在webpack构建中的path包。对我来说,像这样扩展webpack配置有帮助:
{
// rest of the webpack config
resolve: {
// ... rest of the resolve config
fallback: {
"path": require.resolve("path-browserify")
}
},
}
也可以通过npm install path-browserify——save-dev或yarn添加path-browserify——dev来安装path-browserify。
我的环境是这样的:
React => v17 React脚本=> v5 Webpack => v5
要解决这个问题,请遵循下面的说明
1-安装以下软件包
yarn add fs assert https-browserify os os-browserify stream-browserify stream-http react-app-rewired
2-在项目根目录下package.json旁边创建config-coverrides.js
添加以下代码:
const webpack = require('webpack'); module.exports = function override(config, env) { config.resolve.fallback = { url: require.resolve('url'), fs: require.resolve('fs'), assert: require.resolve('assert'), crypto: require.resolve('crypto-browserify'), http: require.resolve('stream-http'), https: require.resolve('https-browserify'), os: require.resolve('os-browserify/browser'), buffer: require.resolve('buffer'), stream: require.resolve('stream-browserify'), }; config.plugins.push( new webpack.ProvidePlugin({ process: 'process/browser', Buffer: ['buffer', 'Buffer'], }), ); return config; }
3-像下面这样修改packages.js
"脚本":{ “start”:“react-app-rewired start”, “build”:“react-app-rewired build”, “test”:“react-app-rewired test” "eject": "react-app-rewired eject" },
新的vue-cli升级(v5)就是这样。为了修复它(空模块的方式),你必须这样改变vue.config.js:
configureWebpack: (config) => {
config.resolve.fallback = {
...config.resolve.fallback,
// Include here the "empty" modules
url: false,
util: false,
querystring: false,
https: false,
};
}