[英]How stop after running react-scripts start?
I started a React app with npm start with start defined in package.json:我用 npm 启动了一个 React 应用程序,开始定义在 package.json 中:
{ "name": "testreactapp", "version": "0.1.0", "private": true, "dependencies": { "react": "^15.6.1", "react-dom": "^15.6.1", "react-scripts": "1.0.10" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } }
I want to stop it now, without closing the terminal.我现在想停止它,而不关闭终端。 How do I do that?
我怎么做?
Tried: npm stop testrectapp but that throws error that it needs a script尝试过:npm 停止 testrectapp 但抛出它需要脚本的错误
Then tried: npm run stop with script "stop": "pkill --signal SIGINT testreactapp" that throws error 'pkill is not recognized as a command'然后尝试:npm run stop with script "stop": "pkill --signal SIGINT testreactapp" that throws error 'pkill is not recognized as a command'
Running ps
in bash
shows:在
bash
运行ps
显示:
PID PPID PGID WINPID TTY UID STIME COMMAND
6652 1 6652 6652 ? 197612 19:52:49 /usr/bin/mintty
1092 1 1092 1092 ? 197612 Jul 25 /usr/bin/mintty
11092 6652 11092 10060 pty1 197612 19:52:49 /usr/bin/bash
13868 1092 13868 992 pty0 197612 Jul 25 /usr/bin/bash
11428 13868 11428 17340 pty0 197612 12:48:27 /usr/bin/ps
11672 1092 1092 11672 ? 197612 Jul 25 /usr/bin/mintty <defunct>
Don't see the app there?在那里看不到应用程序?
Hit your keyboard shortcut for stopping terminal commands (usually Ctrl+C or Ctrl+Q)点击键盘快捷键来停止终端命令(通常是 Ctrl+C 或 Ctrl+Q)
Or, if you don't have input access to the process, identify its PID and kill it :或者,如果您没有对该进程的输入访问权限,请识别其 PID 并终止它:
On Windows :在 Windows 上:
C:\>Taskkill /PID <PID> /F
On Linux :在 Linux 上:
$>kill -SIGTERM <PID>
在你的 package.json 中添加这个:
"stop": "taskkill -F -IM node.exe"
Hitting Ctrl + C
will stop the running app after you provide an answer as Y
as it asks;在您提供
Y
的答案后, Ctrl + C
将停止正在运行的应用程序; No need to close your terminal.无需关闭终端。
I had same issue too.我也有同样的问题。 I used this code to stop it
我用这段代码来阻止它
taskkill -F -IM node.exe
Just type the code in the terminal只需在终端输入代码
If you're using Git Bash you might get an invalid arguments error.如果您使用的是 Git Bash,您可能会收到无效参数错误。 You have to use the following syntax.
您必须使用以下语法。
To check which PID to kill:要检查要杀死的 PID:
netstat -aon
Look for 127.0.0.1:3000 under Local Address and note the PID在本地地址下查找 127.0.0.1:3000 并记下 PID
To kill the process:要杀死进程:
taskkill -f //PID ####
where #### is the PID from above.其中#### 是上面的PID。
I am having the same problem on Mac with a terminal started in VS code.我在使用 VS 代码启动的终端的 Mac 上遇到了同样的问题。
CTRL C kills the node server however a vscode process remains attached to the port afterwards and prevents restarting on the same port. CTRL C 会杀死节点服务器,但是之后一个 vscode 进程仍然连接到该端口,并防止在同一端口上重新启动。
The following workaround works for me on Mac以下解决方法适用于 Mac
npx kill-port 3000 npx 终止端口 3000
You can call this from another terminal and it should kill the node server and any other related vscode processes attached to the port and allow you to restart the server on the same port.您可以从另一个终端调用它,它应该会终止节点服务器和连接到该端口的任何其他相关 vscode 进程,并允许您在同一端口上重新启动服务器。
You can also add a script in package.json:您还可以在 package.json 中添加脚本:
"stop": "npx kill-port 3000" “停止”:“npx 终止端口 3000”
Then call yarn stop to stop your server然后调用 yarn stop 来停止你的服务器
只需使用Ctrl + c
,它就会停止服务器,很简单。
Open Task manager (Task Bar Righ click/press Ctrl + Alt + Delete)打开任务管理器(任务栏右键单击/按 Ctrl + Alt + Delete)
Go on to the Processes tab转到“进程”选项卡
Find the Node.找到节点。 js: Server-side JavaScript
js:服务器端 JavaScript
End the task.结束任务。
working in macOS but cant work ctrl + c
在 macOS 中工作但不能工作
ctrl + c
open a terminal in vs code在 vs code 中打开一个终端
right-click on the terminal OR click on right top zsh-appname右键单击终端或单击右上角的 zsh-appname
click last one kill terminal
单击最后一个
kill terminal
Step by step answer (Windows only; sorry.)...逐步回答(仅限 Windows;抱歉。)...
Step 1 : find processes using the port (port 3000 will be used for the examples here).第 1 步:使用端口查找进程(此处的示例将使用端口 3000)。
netstat -aon | findstr :3000
Output will be something like this: Output 将是这样的:
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 275368
TCP 127.0.0.1:3000 127.0.0.1:52462 ESTABLISHED 275368
TCP 127.0.0.1:52462 127.0.0.1:3000 ESTABLISHED 15760
Step 2 : identify the process ID.第 2 步:识别进程 ID。
We only want tasks which:我们只想要任务:
LISTENING
(fourth column).LISTENING
(第四列)。 In the output above that's line #1, which is process ID 275368 (last column).在上面的 output 中,第 1 行是进程 ID 275368(最后一列)。
Step 3 : kill the process.第三步:杀死进程。
Use taskkill
, with the f
(forceful) flag, to end the process ID from Step 2:使用带有
f
(强制)标志的taskkill
结束步骤 2 中的进程 ID:
taskkill -f -pid 275368
The taskkill
flags are not case sensitive, and they can be set off with a dash or a slash, so these are all equivalent: taskkill -f -pid 275368
, taskkill -F /PID 275368
, taskkill /F /pid 275368
, etc. taskkill
标志不区分大小写,它们可以用破折号或斜线分隔,因此它们都是等效的: taskkill -f -pid 275368
、 taskkill -F /PID 275368
、 taskkill /F /pid 275368
等。
You can try ctrl+z
你可以试试
ctrl+z
After that type npx kill-port <PORT>
之后输入
npx kill-port <PORT>
Usually react start on port 3000, but you better check it out通常 react 在端口 3000 上启动,但你最好检查一下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.