【问题标题】:How does fix this Warning: DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE如何修复此警告:DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE
【发布时间】:2023-01-04 02:56:23
【问题描述】:

如何修复此警告:DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE 在简单的 Create React App 中,当我不使用 Webpack 时

【问题讨论】:

  • 嗨,你能解决这个问题吗??
  • @wasicool2 嗨,不。

标签: reactjs middleware


【解决方案1】:

此问题仅存在于 WebStorm 中。如果您在 Visual Studio Code 中启动,您可以在将近一秒时看到此警告,然后一切正常。

【讨论】:

    【解决方案2】:

    简单的解决方案在这里 在文件中: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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-07
      • 2021-05-11
      • 1970-01-01
      • 1970-01-01
      • 2022-10-31
      • 2019-08-08
      • 2020-11-28
      • 2017-10-25
      相关资源
      最近更新 更多