npm start 不起作用(WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE)

问题描述 投票:0回答:2

我尝试通过

创建一个新的反应应用程序
npx create-react-app myapp    
cd myapp
npm start

我使用的是React版本18.2.0

{
  "name": "myapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },

然后我收到一个错误,我的应用程序也无法在浏览器中打开。 (我尝试手动打开本地主机,但没有成功)

(node:8168) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:8168) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
reactjs npm node-modules
2个回答
1
投票

尝试更改

webpackDevServer.config.js
中的名称,这对我有用。

1.打开node_modules文件夹。
2.搜索 webpackDevServer.config.js。
3.打开js文件并编辑它。

0
投票

我也有同样的疑问,我们如何在部署时做到这一点

© www.soinside.com 2019 - 2024. All rights reserved.