【问题标题】:npm install is giving so many errorsnpm install 给出了很多错误
【发布时间】:2022-01-06 00:59:35
【问题描述】:

我在新买的笔记本电脑上安装了 windows 11,并安装了 Nodejs、Angular Cli,但是当我在我的项目中运行 npm install 时,一切都报错了,我尝试了很多,但无法解决。

升级降级节点。 更新所有节点包。 清除缓存 等等

注意:

node version: v16.13.0
npm version: 8.1.4
angular cli version: Angular CLI: 10.1.7

尝试了所有这些,但无法解决。

帮助我逐步解决问题。

package.json

{
  "name": "public_services",
  "version": "1.0.0",
  "license": "",
  "scripts": {
  "ng": "ng",
  "start": "ng serve",
  "build": "ng build",
  "test": "ng test",
  "lint": "ng lint",
  "e2e": "ng e2e"
 },
 "private": true,
 "dependencies": {
   "@angular/animations": "~10.1.5",
   "@angular/cdk": "^10.2.5",
   "@angular/common": "~10.1.5",
   "@angular/compiler": "~10.1.5",
   "@angular/core": "~10.1.5",
   "@angular/forms": "~10.1.5",
   "@angular/platform-browser": "~10.1.5",
   "@angular/platform-browser-dynamic": "~10.1.5",
   "@angular/router": "10.1.5",
   "@fortawesome/angular-fontawesome": "^0.2.0",
   "@fortawesome/fontawesome-svg-core": "^1.2.28",
   "@fortawesome/free-brands-svg-icons": "^5.13.0",
   "@fortawesome/free-regular-svg-icons": "^5.13.0",
   "@fortawesome/free-solid-svg-icons": "^5.13.0",
   "@ng-bootstrap/ng-bootstrap": "4.1.3",
   "@ng-select/ng-select": "^3.7.3",
   "@ngx-translate/core": "11.0.1",
   "@ngx-translate/http-loader": "4.0.0",
   "@swimlane/ngx-charts": "^19.1.0",
   "@swimlane/ngx-datatable": "^16.0.3",
   "angular-archwizard": "6.1.0",
   "bootstrap": "4.3.1",
   "classlist.js": "1.1.20150312",
   "core-js": "3.1.3",
   "date-fns": "1.30.1",
   "gulp": "4.0.2",
   "hopscotch": "0.3.1",
   "intl": "1.2.5",
   "moment": "2.24.0",
   "ng-lazyload-image": "^9.0.1",
   "ng2-file-upload": "1.3.0",
   "ng2-img-cropper": "0.9.0",
   "ngx-bootstrap": "^5.3.2",
   "ngx-chips": "2.0.0-beta.0",
   "ngx-datatable": "^1.0.3",
   "ngx-dropzone-wrapper": "^9.0.0",
   "ngx-perfect-scrollbar": "7.2.1",
   "ngx-toastr": "10.0.4",
   "node-sass": "^4.14.1",
   "nouislider": "13.1.5",
   "prismjs": "1.16.0",
   "resize-observer-polyfill": "1.5.1",
   "rxjs": "6.6.3",
   "screenfull": "4.2.0",
   "sweetalert2": "8.11.6",
   "tslib": "^2.0.0",
   "web-animations-js": "^2.3.2",
   "xlsx": "^0.16.8",
   "zone.js": "~0.10.2"
 },
   "devDependencies": {
    "@angular-devkit/build-angular": "~0.1001.6",
    "@angular/cli": "~10.1.6",
    "@angular/compiler-cli": "~10.1.5",
    "@angular/language-service": "~10.1.5",
    "@types/core-js": "2.5.0",
    "@types/jasmine": "^3.3.16",
    "@types/jasminewd2": "~2.0.3",
    "@types/jquery": "^3.5.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-cli": "~2.0.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
     "rxjs-compat": "6.5.2",
   "ts-node": "~7.0.0",
   "tslint": "~6.1.0",
   "typescript": "~4.0.3"
  } 
}

npm install 出现错误之后

PS C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend> npm i
npm ERR! code 1
npm ERR! path C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Program Files\nodejs\node.exe C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
npm ERR! Build started 11/29/2021 10:03:34 AM.
npm ERR! MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available tools versions are "4.0".
npm ERR!
npm ERR! Build FAILED.
npm ERR!
npm ERR!   MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available tools versions are "4.0".
npm ERR!
npm ERR!     0 Warning(s)
npm ERR!     1 Error(s)
npm ERR!
npm ERR! Time Elapsed 00:00:00.04
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli   'C:\\Users\\SAYED-SADAT\\Desktop\\data\\coding\\itsm-frontend\\itsm-frontend\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.13.0 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "c:\python27\python.exe" in the PATH
npm ERR! gyp verb `which` failed Error: not found: c:\python27\python.exe
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:13:12)    
npm ERR! gyp verb `which` failed     at F (C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  c:\python27\python.exe Error: not found: c:\python27\python.exe
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:13:12)    
npm ERR! gyp verb `which` failed     at F (C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb could not find "c:\python27\python.exe". checking python launcher
npm ERR! gyp verb check python launcher python executable found: "C:\\Users\\SAYED-SADAT\\.windows-build-tools\\python27\\python.exe"
npm ERR! gyp verb check python version `C:\Users\SAYED-SADAT\.windows-build-tools\python27\python.exe -c "import sys; print "2.7.15
npm ERR! gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 16.13.0
npm ERR! gyp verb command install [ '16.13.0' ]
npm ERR! gyp verb install input version string "16.13.0"
npm ERR! gyp verb install installing version: 16.13.0
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 16.13.0
npm ERR! gyp verb build dir attempting to create "build" dir: C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-sass\build      
npm ERR! gyp verb build dir "build" dir needed to be created? C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-sass\build      
npm ERR! gyp verb Not using VS2017: No usable installation of VS2017 found
npm ERR! gyp verb build/config.gypi creating config file
npm ERR! gyp verb build/config.gypi writing out config file: C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-sass\build\config.gypi
npm ERR! (node:11248) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp verb config.gypi checking for gypi file: C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-sass\config.gypi        
npm ERR! gyp verb common.gypi checking for gypi file: C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-sass\common.gypi        
npm ERR! gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onExit (C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-gyp\lib\build.js:262:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\SAYED-SADAT\\Desktop\\data\\coding\\itsm-frontend\\itsm-frontend\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.13.0npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\SAYED-SADAT\AppData\Local\npm-cache\_logs\2021-11-29T05_33_36_625Z-debug.log

【问题讨论】:

  • This post 可以帮到你。
  • 其实只有1个错误:MSBUILD : error MSB4132: the tools version "2.0" is unrecognized.可用的工具版本为“4.0”。
  • @N.F. ms-build 命令被冻结:npm WARN 已弃用 windows-build-tools@5.2.2:Node.js 现在包含适用于 Windows 的构建工具。您可能不再需要此工具。详情请见github.com/felixrieseberg/windows-build-tools
  • @Bishan 该命令要么冻结不进一步,要么给出如下重命名错误:npm:npm ERR!代码 EBUSY npm 错误!系统调用重命名 npm ERR!路径 C:\Users\SAYED-SADAT\AppData\Roaming\npm\node_modules\windows-build-tools npm ERR! dest C:\Users\SAYED- npm 错误! EBUSY:资源繁忙或锁定,重命名 'C:\Users\SAYED-SADAT\AppData\Roaming\npm\node_modules\windows-build-tools' -> 'C:\Users\SAYED-SADAT\AppData\Roaming\npm\ node_modules\.windows-build-tools-VnpDznvg' npm ERR!可以在以下位置找到此运行的完整日志:

标签: node.js angular npm


【解决方案1】:

npm 能清楚多少?!

错误:未找到:c:\python27\python.exe

一些包需要 python2.7;其他人寻找 python 并会接受 Python 3。这很痛苦;特别是对于我们这些不使用 Python 的人。但您的问题很基本 - 安装 Python 并重试

【讨论】:

  • 但我确实有 Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32 Type "帮助”、“版权”、“学分”或“许可”以获取更多信息。 >>> 帮助
  • 如果npm 找不到它 - 就好像你没有!如果你想要的只是安装 npm 包并转移到 Angular 开发 - 只需在它期望的目录中安装 2.7,然后继续!
  • 好吧,让我试试这个建议。 @菲利克斯;
  • 还是不行。
  • 你是什么意思不工作?是否有 npm 正在寻找的文件?如果有 - 你不会得到同样的错误;如果没有 - 那么你没有安装。没有第三种选择!
【解决方案2】:

这与 package.json 中 node.jsnode-sass 之间的版本不匹配有关。您可以在此处查看所有支持的版本。 https://github.com/sass/node-sass

您将需要更改 node.js 或 node-sass 版本并再次执行 npm install。

【讨论】:

  • 如何查看 sass 版本?
  • 检查您的 package.json 文件。据说您正在使用 "node-sass": "^4.14.1",
  • 感谢 sass 部分在我正在运行的 npm 中正常工作,但它导致 ng serve 命令产生错误。结帐这个问题stackoverflow.com/questions/70150802/…
  • 当然。让我检查那里。如果解决了您的问题,请接受并投票赞成这个答案。
  • 我会这样做,确保问题得到解决。这将帮助其他人找到问题的确切根本原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-26
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 1970-01-01
相关资源
最近更新 更多