javascript - 每次我尝试运行 NPM 安装终端时都会抛出几个错误

标签 javascript node.js angular npm

这是在我的工作笔记本电脑上。我有最新版本的 Angular、Nodejs、Nodesass、VScode,并在本地环境路径中提到了它们。如果我从 Github 下载任何 Angular 模板并尝试进行 NPM 安装,它总是会抛出这些错误。我该如何修复这些错误?

//        gyp verb check python checking for Python executable "python2" in the PATH
//        gyp verb `which` failed Error: not found: python2
//        gyp verb `which` failed     at getNotFoundError (D:\Interview\node_modules\which\which.js:13:12)
//        gyp verb `which` failed     at F (D:\Interview\node_modules\which\which.js:68:19)
//        gyp verb `which` failed     at E (D:\Interview\node_modules\which\which.js:80:29)
//        gyp verb `which` failed     at D:\Interview\node_modules\which\which.js:89:16
//        gyp verb `which` failed     at D:\Interview\node_modules\isexe\index.js:42:5
//        gyp verb `which` failed     at D:\Interview\node_modules\isexe\windows.js:36:5
//        gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:199:21)
//        gyp verb `which` failed  python2 Error: not found: python2
//        gyp verb `which` failed     at getNotFoundError (D:\Interview\node_modules\which\which.js:13:12)
//        gyp verb `which` failed     at F (D:\Interview\node_modules\which\which.js:68:19)
//        gyp verb `which` failed     at E (D:\Interview\node_modules\which\which.js:80:29)
//        gyp verb `which` failed     at D:\Interview\node_modules\which\which.js:89:16
//        gyp verb `which` failed     at D:\Interview\node_modules\isexe\index.js:42:5
//        gyp verb `which` failed     at D:\Interview\node_modules\isexe\windows.js:36:5
//        gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:199:21) {
//        gyp verb `which` failed   code: 'ENOENT'
//        gyp verb `which` failed }
//        gyp verb check python checking for Python executable "python" in the PATH
//        gyp verb `which` succeeded python C:\Program Files (x86)\Python38-32\python.EXE
//        gyp ERR! configure error 
//        gyp ERR! stack Error: Command failed: C:\Program Files (x86)\Python38-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];       
//        gyp ERR! stack   File "<string>", line 1
//        gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
//        gyp ERR! stack                       ^
//        gyp ERR! stack SyntaxError: invalid syntax
//        gyp ERR! stack 
//        gyp ERR! stack     at ChildProcess.exithandler (node:child_process:333:12)
//        gyp ERR! stack     at ChildProcess.emit (node:events:376:20)
//        gyp ERR! stack     at maybeClose (node:internal/child_process:1063:16)
//        gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:295:5)
//        gyp ERR! System Windows_NT 10.0.18363
//        gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\Interview\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
//        gyp ERR! cwd D:\Interview\node_modules\node-sass
//        gyp ERR! node -v v15.5.1
//        gyp ERR! node-gyp -v v3.8.0
//        gyp ERR! not ok
//        Build failed with error code: 1       
//        npm ERR! code ELIFECYCLE
//        npm ERR! errno 1
//        npm ERR! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="157b7a7170386674666655213b24213b24" rel="noreferrer noopener nofollow">[email protected]</a> postinstall: `node scripts/build.js`
//        npm ERR! Exit status 1
//        npm ERR!
//        npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ce2e3e8e9a1ffedffffccb8a2bdb8a2bd" rel="noreferrer noopener nofollow">[email protected]</a> postinstall script.
//        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

最佳答案

我认为您正在使用 Windows 进行开发。一些 Node.js 模块需要在计算机上本地构建。所以,这就是为什么它需要 python 2.x 版本和其他工具。

windows-build-tools package install required tools to build module locally. Go ahead and install this package and after installing it then try again running the command npm install command

关于javascript - 每次我尝试运行 NPM 安装终端时都会抛出几个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65840456/

相关文章:

javascript - 如何在ngFor中实现固定div列?

node.js - 如何使用 Date.now() 修复日期错误

angular - Http拦截器的顺序

javascript - 使用 jquery 禁用表单元素

javascript - 如何创建正则表达式来过滤掉有关长度、大小写和字符类别的复杂条件的结果

javascript - 查找错误 : highlight side menu based on page scrolling position

javascript - 在服务器 JS 上加载部分失败

javascript - 如何使用 useState 和表单正确更新状态?

javascript - req.body 在分配给变量后更改值

javascript - 如何将 JavaScript 对象/数组发送到前端 - node.js 应用程序