javascript - react js如何修改默认端口
问题描述
我可以使用默认端口 3000 启动 react js。但是,当我将端口自定义为 4200 "start": "PORT=4200 react-scripts start"
(只是在 package.json 中更改)时,我无法启动 react js 应用程序。
'PORT' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-app@0.1.0 start: `PORT=4200 react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional lo
ging output above.
npm ERR! A complete log of this run can be found in:
解决方案
要在另一个端口上启动 APP,请运行以下 npm 命令
npm start --port 3002
或在包使用中进行配置
用下面的替换启动命令
"start": "set PORT=3006 && react-scripts start"
推荐阅读
- django - 我可以在 LHS 和 RHS 都是函数的 Django 中执行查询吗?
- python - 缩进错误,意外缩进
- python - “LAB”对象没有属性“audioFilePath”
- javascript - 更改事件无法识别
- time-series - 如何根据条件将时间序列数据集划分为训练和测试?
- laravel - 模拟请求时在单元测试期间未保存数据库条目
- python - 触发 ExternalTaskSensor 时气流卡住
- python - Sqlalchemy.exc.NoReferencedTableError
- java - 尽管有锁,Java 多线程中的意外结果
- openlayers - 格式 GPX.writeFeatures 不写入特征节点