Javascript 运行 react-scripts 后如何停止?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45544145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:05:41  来源:igfitidea点击:

How stop after running react-scripts start?

javascriptnode.jsreactjsreact-scriptspkill

提问by user1837293

I started a React app with npm start with start defined in package.json:

我使用 npm start with start 启动了一个 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 stop 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" 抛出错误“pkill 未被识别为命令”

Edit: running ps in bash shows: 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?

编辑:在 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> 在那里看不到应用程序?

采纳答案by Antoine Auffray

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>

回答by rhel.user

Add this in your package.json:

在你的 package.json 中添加:

"stop": "taskkill -F -IM node.exe"

回答by Satish Patel

Hitting Ctrl + Cwill stop the running app after you provide an answer as Yas it asks; No need to close your terminal.

Ctrl + C在您Y按要求提供答案后,点击将停止正在运行的应用程序;无需关闭终端。

回答by ABODE

I had same issue too. I used this code to stop it

我也有同样的问题。我用这段代码来阻止它

taskkill -F -IM node.exe

Just type the code in the terminal

只需在终端中输入代码

回答by canvasD

If you're using Git Bash you might get an invalid arguments error. You have to use the following syntax.

如果您使用 Git Bash,您可能会收到无效参数错误。您必须使用以下语法。

To check which PID to kill:

要检查要杀死的 PID:

netstat -aon

Look for 127.0.0.1:3000 under LocalAddress and note the PID

本地地址下查找 127.0.0.1:3000并记下 PID

To kill the process:

杀死进程:

taskkill -f //PID ####

where #### is the PID from above.

其中#### 是上面的PID。