您可以通过 2 种方式解决此问题。
- 删除 node_module 然后在运行npm install后将您的react-scripts版本从“5.0.0”更改为“4.0.3”。
或者
1-安装这些软件包。
npm install 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;
}