【问题标题】:i get an error related to gyp when i try to do npm install当我尝试执行 npm install 时,出现与 gyp 相关的错误
【发布时间】:2021-11-14 18:42:51
【问题描述】:

我刚刚开始编辑 NodeJS 项目,我使用 npm install 安装了所有需要的库。 但它返回与gyp 相关的错误,我尝试了很多方法来解决它但没有用,我安装了 python v3.9,节点 v16.4,我使用 windows10。

npm ERR! code 1
npm ERR! path C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\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\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node
_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
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\\fiberx\\Downloads\\teliaty2001-attachments\\cw3_tp02-MariaIchtar-master (1)\\cw3_tp02-MariaIchtar-master\\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.4.2 | 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 "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-maste
r\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\
which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\
which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\whi
ch\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\ise
xe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\ise
xe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:195:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-maste
r\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\
which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\
which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\whi
ch\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\ise
xe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\ise
xe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:195:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` succeeded python C:\Users\fiberx\AppData\Local\Programs\Python\Python39\python.EXE
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:\Users\fiberx\AppData\Local\Programs\Python\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3
];
npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack                       ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:397:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1067:16)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\fiberx\\Downloads\\teliaty2001-attachments\\cw3_tp02-MariaIchtar-master (1)\\cw3_tp02-Mari
aIchtar-master\\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\fiberx\Downloads\teliaty2001-attachments\cw3_tp02-MariaIchtar-master (1)\cw3_tp02-MariaIchtar-master\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.4.2
npm 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\fiberx\AppData\Local\npm-cache\_logs\2021-11-14T09_49_21_736Z-debug.log

你能帮我解决吗?

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: node.js npm npm-install node-gyp gyp


【解决方案1】:

node-sass 导致您的npm install 错误。

原因:

node-sass 是一个 npm 包,使用 C/C++ 构建,安装后需要安装预构建的二进制文件或从源代码编译。

在您的情况下,未成功下载预构建的二进制文件,因此 npm 尝试从源代码构建 node-sass,这需要 python2.但是你的系统没有安装python2。

解决方案:

要解决此问题,您有 3 个选项:

  1. 修复你的网络配置(从 Github 下载预构建文件)或使用sass_binary_site 更改 node-sass 预构建二进制站点,例如在中国你可以尝试淘宝镜像:sass_binary_site=https://npm.taobao.org/mirrors/node-sass。如果 npm 可以下载预编译的文件,就不会再编译了。
  2. 安装python2。
  3. 将 npm 依赖项从 c/c++ node-sass 更改为纯 JavaScript 替代方案,例如 sass

【讨论】:

    猜你喜欢
    • 2013-09-17
    • 2021-08-26
    • 2022-07-26
    • 2023-02-04
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多