【问题标题】:Node & React - npm start - is running BUT localhost:3000 "cant be reached"Node & React - npm start - 正在运行但 localhost:3000 “无法访问”
【发布时间】:2020-08-31 10:55:59
【问题描述】:

(具有节点版本 12 和 npm 版本 6)

  • 后端:Node.js
  • 前面:React.js 我克隆了存储库 cd 进入目录 跑了

npm install (installing dependencies etc...)

当我跑的时候

npm start

我得到了

[Ben@Mac:~/Desktop/test]$ npm start

> answers-entry-level-exam@1.0.0 start /Users/Ben/Desktop/test
> lerna run start --parallel

lerna notice cli v3.22.1
lerna info Executing command in 1 package: "npm run start"
@ans-exam/server: > @ans-exam/server@1.0.0 start 
/Users/Ben/Desktop/test/server
@ans-exam/server: > ts-node-dev index.ts
@ans-exam/server: Using ts-node version 8.5.2, typescript version 3.7.2
@ans-exam/server: server running 3232
  • 看来服务器运行正常
  • 但无法访问 localhost:3000 不打开任何东西 第一次打开时,屏幕右侧出现与节点相关的 MacOS 弹出窗口(我认为这是问题,但不知道如何解决)

我的 package.json:

{
 "name": "answers-entry-level-exam",
 "version": "1.0.0",
 "description": "",
 "main": "index.js",
 "scripts": {
 "b": "npm run bootstrap",
 "bootstrap": "lerna bootstrap",
 "test": "echo \"Error: no test specified\" && exit 1",
 "start": "lerna run start --parallel",
 "postinstall": "npm run bootstrap"
},
 "author": "",
 "license": "ISC",
 "devDependencies": {
 "lerna": "^3.22.1"
}
}

谢谢!

【问题讨论】:

  • 如果您不使用任何框架,请直接在代码中更改您的端口。否则,如果您使用 ExpressJS 之类的框架,请尝试在终端中设置变量 PORT=3000。另一方面,您可能没有关闭之前正在运行的应用程序并且您的操作系统已经在使用该端口(这很奇怪,因为它也应该显示在您的终端中)。
  • 框架是 Express,在端口 3232(即后端)上运行,例如 localhost:3232/api/tickets 工作正常,但前端无法上传
  • 你为前端克隆了哪个 repo?

标签: node.js reactjs npm lerna npm-start


【解决方案1】:

尝试 localhost:3232。我在你的输出中看到server running 3232

【讨论】:

  • 如果我没记错的话就是后端(Node)的端口
【解决方案2】:

我再次克隆了 repo,它修复了这个问题 向所有试图提供帮助的人干杯:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-09
    • 2020-06-23
    • 1970-01-01
    • 2019-11-23
    • 2010-10-07
    • 1970-01-01
    • 2019-05-05
    • 2012-11-03
    相关资源
    最近更新 更多