【发布时间】:2021-05-17 12:06:21
【问题描述】:
我在 vscode 上使用 nextjs。我使用npm run dev 在localhost:3000 中启动我的服务器,然后使用^Z 暂停npm run dev。然后我使用npm run dev 再次启动我的服务器,但收到以下错误
Port 3000 is already in use.
npm ERR! code 1
npm ERR! path /Users/lee33ya/Desktop/game
npm ERR! command failed
npm ERR! command sh -c next dev
关闭 vscode 并再次运行npm run dev 后,一切正常。但是关闭vscode真的很烦人,这样我就可以再次执行npm run dev。我试过杀死端口,但问题仍然存在。 (在运行npm run dev、挂起并运行npm run dev 后,错误重复出现)。以下是完整错误的日志
0 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'dev' ]
1 info using npm@7.5.4
2 info using node@v12.18.4
3 timing config:load:defaults Completed in 5ms
4 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 2ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/Users/lee33ya/Desktop/game/.npmrc Completed in 1ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/lee33ya/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 1ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 14ms
19 verbose npm-session 14f27a79b0b3ed1a
20 timing npm:load Completed in 23ms
21 timing command:run-script Completed in 1973ms
22 verbose stack Error: command failed
22 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
22 verbose stack at ChildProcess.emit (events.js:315:20)
22 verbose stack at maybeClose (internal/child_process.js:1021:16)
22 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
23 verbose pkgid game@0.1.0
24 verbose cwd /Users/lee33ya/Desktop/game
25 verbose Darwin 20.2.0
26 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
27 verbose node v12.18.4
28 verbose npm v7.5.4
29 error code 1
30 error path /Users/lee33ya/Desktop/game
31 error command failed
32 error command sh -c next dev
33 verbose exit 1
下面是我的package.json
{
"name": "game",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "10.0.6",
"react": "17.0.1",
"react-dom": "17.0.1"
},
"devDependencies": {
"@types/node": "^14.14.27",
"@types/react": "^17.0.2",
"typescript": "^4.1.5"
}
}
我在其他项目中使用过 nextjs,但这个问题最近才出现...我做错了什么?
【问题讨论】:
-
不要使用
npm run dev,因为它已经在运行,请尝试fg(来自bash 的内部命令)来恢复暂停的进程。
标签: node.js npm visual-studio-code next.js