【问题标题】:When launching react / express application, an extra port is launched启动 react / express 应用程序时,会启动一个额外的端口
【发布时间】:2021-06-19 12:00:55
【问题描述】:

当我运行我的 react / express 应用程序时,它首先在端口上启动,并且仅在启动 3000(客户端)和 8000(服务器)端口之后。这是它输出到控制台的内容 ==========> [1] i 「wds」: 项目在http://192.168.0.102/运行

[0] Express server is running on port 8000
[1] i 「wds」: Project is running at http://192.168.0.102/        
[1] i 「wds」: webpack output is served from
[1] i 「wds」: Content not from webpack is served from C:\Users\allek\OneDrive\Desktop\iron_react\ironcage\iron_react\client\public
[1] i 「wds」: 404s will fallback to /
[1] Starting the development server...
[1]
[1] Compiled successfully!
[1]
[1] You can now view client in the browser.
[1]
[1]   Local:            http://localhost:3000
[1]   On Your Network:  http://192.168.0.102:3000
[1]
[1] Note that the development build is not optimized.
[1] To create a production build, use yarn build.

这是我的 package.json 开始设置

 "scripts": {
    "client-install": "cd client && yarn install",
    "backend": "node server.js",
    "server": "nodemon server.js",
    "client": "cd client && npm start",
    "start": "concurrently \"yarn run server\" \"yarn run client\""
  }

这是我的 webpack 配置覆盖设置(但这在问题中不起作用)

  const {
  override,
  fixBabelImports,
  overrideDevServer,
  addLessLoader
} = require('customize-cra');

const devServerConfig = () => config => {
  return {
    ...config,
    open: true,
    overlay: true,
    compress: true,
    host: 'localhost',
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://localhost:8000/',
        secure: false
      },
    },
  }
}


module.exports = {
  webpack: override(
    fixBabelImports('import', {
      libraryName: 'antd',
      libraryDirectory: 'es',
      style: true,
    }),
    addLessLoader({
      javascriptEnabled: true,
      modifyVars: {},
    }),
  ),
  devServer: overrideDevServer(
    devServerConfig()
  )
};

【问题讨论】:

    标签: reactjs express webpack


    【解决方案1】:

    发生这种情况是因为 create-react 应用程序在我的项目准备就绪时会在新窗口中打开,但在 config-override 中我也打开它但无需等待,所以我只是在 config override 中删除 open in new window

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 2017-10-11
      • 2018-10-27
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      相关资源
      最近更新 更多