我在 Git Bash(在 Windows 11 上)上使用 Node.js 时遇到问题。当我运行时
npm install --save puppeteer
或类似的命令,我收到以下错误消息:
npm ERR! code 1
npm ERR! path C:\Users\{user}\git-repos\book-scraper\node_modules\puppeteer
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node install.js
npm ERR! 'node' is not recognized as an internal or external command,
npm ERR! operable program or batch file.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\{user}\AppData\Local\npm-cache\_logs\2022-08-18T20_26_25_630Z-debug-0.log
我仔细检查了 Node 是否包含在我的 Path 变量中。我尝试包含 Node 目录和node.exe 的路径。当我在 Powershell 或 Windows 终端中运行相同的命令时,该命令可以正常工作。我还检查了日志 - 这是日志文件的相关部分:
365 verbose pkgid <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed9d989d9d889988889faddcdbc3dcc3dc" rel="noreferrer noopener nofollow">[email protected]</a>
366 verbose cwd C:\Users\{user}\git-repos\book-scraper
367 verbose Windows_NT 10.0.22000
368 verbose node v16.15.0
369 verbose npm v8.17.0
370 error code 1
371 error path C:\Users\{user}\git-repos\book-scraper\node_modules\puppeteer
372 error command failed
373 error command C:\WINDOWS\system32\cmd.exe /d /s /c node install.js
374 error 'node' is not recognized as an internal or external command,
374 error operable program or batch file.
375 verbose exit 1
如果有人能提供任何帮助,我将不胜感激!
最佳答案
而不是打开git bash
从 Windows 资源管理器上下文菜单中,打开 Windows 终端( Node 在其中工作)并且:
- 确保您的 %PATH% 还包含
C:\Program Files\Git\bin\
(之前C:\Windows\System32
) - 输入“
bash
”(进入 Git bash session ) - 检查 Node 是否被
which node
识别
关于node.js - Git Bash 找不到 node.js,即使它在我的路径中并且可以在 Powershell 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73409178/