简体   繁体   English

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

[英]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'

Edit编辑

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只需在终端输入代码

To make sure the process it finished just type the command:要确保它完成的过程只需键入命令:

$ killall -9 node

Will kill all processes by with the name "node".将使用名称“node”杀死所有进程。 -9 to use kernel for killing the process, instead of process itself. -9使用内核杀死进程,而不是进程本身。

See the manpage请参阅手册页

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 ,它就会停止服务器,很简单。

  1. Open Task manager (Task Bar Righ click/press Ctrl + Alt + Delete)打开任务管理器(任务栏右键单击/按 Ctrl + Alt + Delete)

  2. Go on to the Processes tab转到“进程”选项卡

  3. Find the Node.找到节点。 js: Server-side JavaScript js:服务器端 JavaScript

  4. End the task.结束任务。

working in macOS but cant work ctrl + c在 macOS 中工作但不能工作ctrl + c

  1. open a terminal in vs code在 vs code 中打开一个终端

  2. right-click on the terminal OR click on right top zsh-appname右键单击终端或单击右上角的 zsh-appname

  3. 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:我们只想要任务:

  1. Are TCP (first column), and是 TCP(第一列),
  2. Show port 3000 (second column), and显示端口 3000(第二列),以及
  3. Are 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 275368taskkill -F /PID 275368taskkill /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.

相关问题 了解 react-scripts 如何开始工作 - Understanding how react-scripts start work react-scripts 启动错误(找不到模块'../scripts/start') - 我该如何解决这个问题? - react-scripts start error (Cannot find module '../scripts/start') - how can i fix this? 反应:“反应脚本启动”找不到模块 webpack - React: "react-scripts start" cannot find module webpack React 应用程序在使用 react-scripts start 运行时工作正常,但在构建时出现“意外语法错误:意外令牌:<” - React app works fine when running with react-scripts start but gets a "Unexpected SyntaxError: Unexpected Token: <" when built 如何在开发服务器中为 react-scripts 启动调用定义基本 URL - how to define base URL in the dev server for react-scripts start call React-react-scripts publicPath - React - react-scripts publicPath 如何在没有 react-scripts 的情况下运行 React.js 应用程序? - How to run React.js app without react-scripts? react-scripts babel 脚本在本地反应应用程序上使用纱线运行时出错 - react-scripts babel scripts error running with yarn on local react application 为什么“npm start”有效,但“npm start”显然执行的“react-scripts start”无效? - Why does "npm start" work but not "react-scripts start" which is what "npm start" apparently executes? 在 CRA/react-scripts 中使用可选链接 (?.) - using optional chaining(?.) with CRA/react-scripts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM