NodeJS 在Google Cloud VM上运行2个不同的reactJS前端,访问端口出现问题

u0njafvf  于 2023-05-28  发布在  Node.js
关注(0)|答案(1)|浏览(110)

我目前正在Google Cloud VM示例上测试ReactJS前端的多个版本。我通过将package.json文件中的“scripts”部分更改为“start”成功设置了第一个版本:“react-scripts start --host 0.0.0.0“。但是,我在运行第二个版本时遇到了问题。
对于第二个版本,我尝试将package.json中的“start”脚本更改为“react-scripts start --host 0.0.0.0--port 4000”,并将第一个版本的端口保持为3000。很不幸,没有成功。
我还在第二个版本的目录中运行了npm install,但遇到了一个错误:

npm ERR! code EJSONPARSE
npm ERR! file /home/USERNAME/frontendv2reactjs/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 775 while parsing '{
npm ERR! JSON.parse   "name": "NAME",
npm ERR! JSON.parse   "version": '
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

如果您能帮助解决这些问题,并在Google Cloud VM示例上与第一个版本一起运行第二个版本,我们将不胜感激。非常感谢!

u5i3ibmn

u5i3ibmn1#

从错误消息:

npm ERR! code EJSONPARSE
npm ERR! file /home/USERNAME/frontendv2reactjs/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 775 while parsing '{
npm ERR! JSON.parse   "name": "NAME",
npm ERR! JSON.parse   "version": '
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

错误似乎是v2前端中的版本标识符。在指定版本时,看起来你可能在JSON中遗漏了一个'字符,和/或该行末尾的逗号。详细了解/home/USERNAME/frontendv2reactjs/package.json
否则,在react-scripts documentation中,考虑使用变量PORT而不是命令行参数以保持一致性。在本地运行notes --port时,我找不到任何可以工作的东西。这可能是错误的,只是很难从他们的网站上获得好的文档。尝试:

PORT=4000 react-scripts start --host 0.0.0.0

相关问题