reactjs 如何修复此警告:部署网络备份开发服务器在设置中间件之后打开

sz81bmfz  于 2023-01-04  发布在  React
关注(0)|答案(2)|浏览(150)

如何修复此警告:在简单Create React应用程序中以及不使用Webpack时的DEP_WEBACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE

juzqafwq

juzqafwq1#

这个问题只在WebStorm中出现。如果你在Visual Studio代码中启动,你可以在接近一秒钟的时间内看到这个警告,然后一切正常。

uemypmqf

uemypmqf2#

简单的解决方案在这里在文件:node_modules/react-scripts/config/webpackDevServer.config.js

更改此代码

onBeforeSetupMiddleware(devServer) { // Keep evalSourceMapMiddleware// middlewares beforeredirectServedPath` otherwise will not have any effect
// This lets us fetch source contents from webpack for the error overlay
devServer.app.use(evalSourceMapMiddleware(devServer));

if (fs.existsSync(paths.proxySetup)) {
// This registers user provided middleware for proxy reasons
require(paths.proxySetup)(devServer.app);
}
},
onAfterSetupMiddleware(devServer) {
// Redirect to PUBLIC_URL or homepage from package.json if url not match
devServer.app.use(redirectServedPath(paths.publicUrlOrPath));

// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// We do this in development to avoid hitting the production cache if
// it used the same host and port.
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
}

来自

setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined')
}

if (fs.existsSync(paths.proxySetup)) {
    require(paths.proxySetup)(devServer.app)
}

middlewares.push(
    evalSourceMapMiddleware(devServer),
    redirectServedPath(paths.publicUrlOrPath),
    noopServiceWorkerMiddleware(paths.publicUrlOrPath)
)

return middlewares;
}

相关问题