简体   繁体   English

将 webpack 4 更新为 webpack 5 在现有的 create-react-app 上用 react-app-rewired 弹出

[英]Update webpack 4 to webpack 5 on an existing create-react-app ejected with react-app-rewired

I have an existing old react application, created with create-react-app and ejected with react-app-rewired .我有一个现有的旧 React 应用程序,使用create-react-app并使用react-app-rewired弹出。 I'm updating the deprecated dependencies.我正在更新已弃用的依赖项。 I've already updated react-scripts to the current version (4.0.3) and everything works fine.我已经将react-scripts更新到当前版本 (4.0.3),一切正常。 But I need to update the style-loader lib, and this new version requires webpack 5.但是我需要更新style-loader库,这个新版本需要 webpack 5。

The current react-scripts version is using webpack 4:当前的react-scripts版本正在使用 webpack 4:

> npm ls webpack
my-app@0.1.0
└─┬ react-scripts@4.0.3
  └── webpack@4.44.2 

I found a project named webpack-5-react-script : https://www.npmjs.com/package/webpack-5-react-scripts .我找到了一个名为webpack-5-react-script的项目: https://www.npmjs.com/package/webpack-5-react-scripts It seems what I need, but as my project was ejected using react-app-rewired a long time ago, I get this error when I run npm start :这似乎是我需要的,但是由于我的项目很久以前就使用react-app-rewired被弹出,所以当我运行npm start时出现此错误:

Error: Cannot find module 'react-scripts/package.json'
Require stack:
- /home/.../my-app/node_modules/react-app-rewired/scripts/utils/paths.js
- /home/../my-app/node_modules/react-app-rewired/scripts/start.js

What I can do?我可以做什么? Has anybody faced this issue?有人遇到过这个问题吗?

React app rewired start, calls react-scripts start, you would need to edit react app rewired to call webpack5-react-scripts instead. React app rewired start,调用 react-scripts start,您需要编辑 react app rewired 以调用 webpack5-react-scripts。

Just download react-scripts 5.0.0 into your project?只需将 react-scripts 5.0.0 下载到您的项目中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM