React native change listening port

前端 未结 13 1363
既然无缘
既然无缘 2020-12-05 17:36

I am using react native android and having face issues to deploy the app on an android device. When I run

react-native start, it won\'t start dev server

13条回答
  •  暖寄归人
    2020-12-05 17:42

    I know it is late but FYI, there is also another way where you can change your port permanently.

    Go to your_app\node_modules\react-native\local-cli\server\server.js and change the port 8081 to 8088

    which will be something like this

        ...
          module.exports = {
          name: 'start',
          func: server,
          description: 'starts the webserver',
          options: [{
            command: '--port [number]',
            default: 8088,
            parse: (val) => Number(val),
          }
         ...
    

    UPDATE TESTED ON RN 0.57:
    1. If you are using custom metro config

    const config = {
      ...
      server: {
        port: 8088,
      }
      ...
    };
    

    2. And if you are not then,
    Go to your_app\node_modules\react-native\local-cli\util\Config.js

    const Config = {
       ...
       server: {
          port: process.env.RCT_METRO_PORT || 8088 //changed from 8081
       }
       ...
    }
    

提交回复
热议问题