NodeJS npm安装npm ERR!失败的gyp动词错误:页面未找到

lawou6xi  于 2023-01-16  发布在  Node.js
关注(0)|答案(1)|浏览(173)

在Ubuntu 21.10上,实际上没有安装Python2.x,当我在一个大项目上执行“npm install”时,我遇到了以下错误(package.json很大,但这两行可能是相关的:

...
  "devDependencies": {
    ...
    "sass": "^1.46.0",
    "sass-loader": "10.1.1",
...

$ npm install

npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/username/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN old lockfile 
npm ERR! npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm ERR! npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm ERR! npm WARN old lockfile 
npm ERR! npm WARN old lockfile This is a one-time fix-up, please be patient...
npm ERR! npm WARN old lockfile 
npm ERR! npm WARN deprecated <many many warnings...>
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-sass
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c node scripts/build.js
npm ERR! npm ERR! Building: /usr/bin/node /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! npm ERR! gyp info it worked if it ends with ok
npm ERR! npm ERR! gyp verb cli [
npm ERR! npm ERR! gyp verb cli   '/usr/bin/node',
npm ERR! npm ERR! gyp verb cli   '/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/bin/node-gyp.js',
npm ERR! npm ERR! gyp verb cli   'rebuild',
npm ERR! npm ERR! gyp verb cli   '--verbose',
npm ERR! npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! npm ERR! gyp verb cli   '--libsass_library='
npm ERR! npm ERR! gyp verb cli ]
npm ERR! npm ERR! gyp info using node-gyp@3.8.0
npm ERR! npm ERR! gyp info using node@16.14.0 | linux | x64
npm ERR! npm ERR! gyp verb command rebuild []
npm ERR! npm ERR! gyp verb command clean []
npm ERR! npm ERR! gyp verb clean removing "build" directory
npm ERR! npm ERR! gyp verb command configure []
npm ERR! npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! npm ERR! gyp verb `which` failed     at getNotFoundError (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:13:12)
npm ERR! npm ERR! gyp verb `which` failed     at F (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:68:19)
npm ERR! npm ERR! gyp verb `which` failed     at E (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:80:29)
npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:89:16
npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/index.js:42:5
npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/mode.js:8:5
npm ERR! npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! npm ERR! gyp verb `which` failed     at getNotFoundError (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:13:12)
npm ERR! npm ERR! gyp verb `which` failed     at F (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:68:19)
npm ERR! npm ERR! gyp verb `which` failed     at E (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:80:29)
npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:89:16
npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/index.js:42:5
npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/mode.js:8:5
npm ERR! npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
npm ERR! npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! npm ERR! gyp verb `which` failed }
npm ERR! npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! npm ERR! gyp verb `which` succeeded python /usr/bin/python
npm ERR! npm ERR! gyp ERR! configure error 
npm ERR! npm ERR! gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! npm ERR! gyp ERR! stack                       ^
npm ERR! npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! npm ERR! gyp ERR! stack 
npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:399:12)
npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
npm ERR! npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
npm ERR! npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! npm ERR! gyp ERR! System Linux 5.15.0-18-generic
npm ERR! npm ERR! gyp ERR! command "/usr/bin/node" "/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! npm ERR! gyp ERR! cwd /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-sass
npm ERR! npm ERR! gyp ERR! node -v v16.14.0
npm ERR! npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! npm ERR! gyp ERR! not ok 
npm ERR! npm ERR! Build failed with error code: 1

特别是,这一行不是有效的Python3.x synthax:import sys; print "%s.%s.%s" % sys.version_info[:3];,所以即使 * 伪造 * 一个名为'python'或'python 2'的符号链接,它指向系统上的-〉'/usr/bin/python3.9',自然也没有帮助。
npm cache clean --force也没有帮助。
系统信息:

$ npm --version
8.3.1
$ node --version
v16.14.0
$ uname -mor
5.15.0-18-generic x86_64 GNU/Linux

关于我可以做些什么来修复这个错误有什么提示吗?

mkshixfv

mkshixfv1#

我面临着类似的问题,并解决它没有安装佩顿在所有。可能这种方式帮助你。
sass-loader要求您安装Dart SassNode-Sass,我使用了Node-Sass,并在启动npm install之前手动安装了它。
因此我的步骤:
1.删除节点模块
1.删除包-lock.json

  1. npm安装节点-sass@
  2. npm安装
    请考虑以下几点:
  • node-sass版本必须与Node.js版本相对应。下面是node-sass支持的最低和最高版本的快速指南:

| NodeJS |支持的节点sass版本|节点模块|
| - ------|- ------|- ------|
| 节点16|6.0以上|九十三|
| 节点15|5.0以上|八十八|
| 节点14|4.14岁以上|八十三|
| 节点13|4.13+,〈5.0|七十九|
| 节点12|4.12以上|七十二|
| 节点11|4.10+,〈5.0|六十七|
| 节点10|4.9+,〈6.0|六十四|
| 节点8|4.5.3以上,〈5.0|五十七|
| 淋巴结〈8|小于5.0|57岁以下|

  • 目前,Node Sass已被弃用,因此我建议使用Dart Sass

值得一提的是,快速更改nodejs版本的简单方法是使用nvm

相关问题