簡體   English   中英

嘗試在 Mac 上本地運行 Rails + React 應用程序時,如何修復“端口已在使用”錯誤?

[英]How can you fix a 'port already in use' error while trying to run a Rails + React app locally on a Mac?

我正在開發一個基於的示例 react/rails 應用程序。 在出現此問題之前幾天它工作正常,我無法弄清楚是什么原因導致它或如何解決它。

對於我嘗試在其上運行 web 服務器的任何端口,我都會得到這種行為。

這種事情沒有列出要殺死的進程: lsof -nP -iTCP:3000| grep LISTEN lsof -nP -iTCP:3000| grep LISTEN

這也顯示沒有結果: lsof -i tcp:3000

似乎反應開始正常(在 3000 上),然后 rails 開始(在 3001 上)然后有某種碰撞導致它關閉。

這是我正在使用的 Procfile.dev:

web: PORT=3000 yarn --cwd client run start
api: PORT=3001 bundle exec rails s

react 應用程序位於 rails 應用程序的/client目錄中。

這是來自反應應用程序package.json的代理行: "proxy": "http://localhost:3001/",

這是終端output:

$ bin/rake start
Running via Spring preloader in process 41869
[OKAY] Loaded ENV .env File as KEY=VALUE Format
12:38:45 PM web.1 |  yarn run v1.22.4
12:38:45 PM web.1 |  $ react-scripts start
12:38:46 PM api.1 |  => Booting Puma
12:38:46 PM api.1 |  => Rails 6.0.3.1 application starting in development 
12:38:46 PM api.1 |  => Run `rails server --help` for more startup options
12:38:46 PM web.1 |  Something is already running on port 3000.
12:38:46 PM web.1 |  Done in 1.06s.
[DONE] Killing all processes with signal  SIGINT
12:38:46 PM web.1 Exited Successfully
12:38:46 PM api.1 |  Exiting
12:38:46 PM api.1 Exited Successfully

rake 任務( lib/tasks/start.rake )是:

namespace :start do
  task :development do
    exec 'heroku local -f Procfile.dev'
  end
end

desc 'Start development server'
task :start => 'start:development'

謝謝參觀!

在運行npm start之前執行export PORT = 'portNumber' (不帶引號)

我最終只是擦除了 repo 並克隆了舊版本。 現在一切正常,我只是失去了一天的工作。 我認為這對我來說已經足夠好了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM