首页 > 解决方案 > 如何更改反应应用程序中的默认端口并为其定义特定端口

问题描述

React 应用程序获得了端口 8080,目前我们无法使用。

如何更改默认端口号。

这是运行命令 npm start 时显示的错误

**注意:也许这可能是一个不同的问题,对反应开发有点新


events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES 127.0.0.1:8080
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at Server.setupListenHandle [as _listen2] (net.js:1350:19)
    at listenInCluster (net.js:1408:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1517:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! redux-simple-starter@1.0.0 start: `node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the redux-simple-starter@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\harsha94\AppData\Roaming\npm-cache\_logs\2019-05-25T16_59_11_280Z-debug.log ```

标签: reactjs

解决方案


  • 在您的 package.json 文件中添加以下行

    "scripts": { "start": "PORT=5600 react-scripts start",

  • npm 安装

  • npm 开始

推荐阅读