[英]React App not connectiong to local server
I have my local express server running at port 3000, when I npm start
my react app, it asks to Would you like to run the app on another port instead? Yes
我有我的本地快递服务器在端口 3000 上运行,当我
npm start
我的反应应用程序时,它询问Would you like to run the app on another port instead? Yes
Would you like to run the app on another port instead? Yes
but takes forever and doesn't take me anywhere. Would you like to run the app on another port instead? Yes
的,但需要永远,不会带我去任何地方。 I tried to set port of my react app in package.json but then it's not responding to the server.我试图在 package.json 中设置我的反应应用程序的端口,但它没有响应服务器。
Thanks in advance提前致谢
You can set your React app port in your package.json scripts:您可以在 package.json 脚本中设置您的 React 应用程序端口:
replace your script替换你的脚本
"start": "react-scripts start"
with和
"start": "set PORT=8080 && react-scripts start"
Should work with a different port value to stop conflicts.应该使用不同的端口值来停止冲突。
Make sure your port can be specified with this line确保可以使用此行指定您的端口
app.set('port', process.env.PORT || 3000);
then set something in your env然后在你的环境中设置一些东西
PORT=8080
Change your port like this in your package.json
file在
package.json
文件中像这样更改端口
"scripts": {
"start": "set PORT=3006 && react-scripts start"
},
If you are using a .env
file, I suggest you use @Joe Lloyd his answer.如果您使用的是
.env
文件,我建议您使用@Joe Lloyd 他的答案。 If not, my answer should do the trick.如果没有,我的回答应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.