突然在我的一个jenkins环境构建已经开始失败,而在本地机器,它似乎工作得很好,因为我有python安装,

从日志中,我能够检测到问题是内部依赖关系,即node-gyp v3.5.0从node-sass v3.8.0,当我通过访问这篇关于node-gyp的文章进行研究时,我发现了Python需要安装的先决条件。

所以我的问题是,我可以安装哪个版本的node-sass来绕过这个,或者有更好的解决方案,因为我的构建在相同的环境上运行良好,直到今天早上。

节点v5.10.1

错误日志

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 (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\index.js:44:5
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\windows.js:29:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:82:15)
gyp verb `which` failed  python2 { [Error: not found: python2] code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` failed Error: not found: python
gyp verb `which` failed     at getNotFoundError (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\index.js:44:5
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\windows.js:29:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:82:15)
gyp verb `which` failed  python { [Error: not found: python] code: 'ENOENT' }
gyp verb could not find "python". checking python launcher 
gyp verb could not find "python". guessing location 
gyp verb ensuring that file exists: C:\Python27\python.exe
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at Object.failNoPython (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\node-gyp\lib\configure.js:454:19)
gyp ERR! stack     at Object.<anonymous> (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\node-gyp\lib\configure.js:480:16)
gyp ERR! stack     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:82:15)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files (x86)\\Jenkins\\jobs\\NdbSite-hot-fix-Manual-PreBuild\\workspace\\src\\NdbSite.UI\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\node-sass
gyp ERR! node -v v5.10.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok 
Build failed

任何想法都非常感激,谢谢。


当前回答

我在一台Windows 11机器上,为了修复它,我自己下载了python27,使用这个链接:https://www.python.org/download/releases/2.7/。

安装完成后,我运行了这个命令:

npm config set python c:\python27\python.exe

其他回答

下面是帮助我防止在运行基于旧node-gyp v3.8.0的项目时出现错误error: not found: python2的方法。

运行npm install——global——production windows-build-tools@4.0.0 将python.exe重命名为%USERPROFILE%\.windows-build-tools\python27中的python2.exe 确保%USERPROFILE%\。windows-build-tools\python27是PATH环境变量的一部分(这是windows-build-tools应该已经为你做的) 下载Visual Studio 2017构建工具 告诉npm使用VS 2017, npm配置msvs_version 2017 运行使用node-gyp的脚本(node-gyp现在会找到python2.exe)

可选:强制升级node-gyp

您还可以尝试将项目升级为使用node-gyp v8.0.0而不是node-gyp v3.8.0。在这种情况下,在package.json中添加以下决议项:

  "resolutions": {
    "node-gyp": "8.0.0"
  }

之后,确保安装了Python 3和Visual Studio 2017构建工具和/或Visual Studio 2019构建工具。你也可以执行npm config delete msvs_version命令让node-gyp自动检测你的VS版本。

测试:

Windows 10 Pro Build 19042.985 node . js v15.14.0 npm v7.7.6 Node-gyp -v v3.8.0。

我的操作系统是win10 x64。 在进行npm安装时也发现了类似的问题。

检查节点版本号是否与node-sass版本号一致。(参考以上表格)如果需要,升级或降级节点版本 删除“node_modules”文件夹 install node-sass@ $ NPM install

做得很好。

节点15.x。X,和"node-sass": "^4.11.0"。 我在node-sass的发布说明中看到了node-sass 4.11.0兼容的节点最高版本是11,所以我卸载了node并重新安装11.15.0版本(我使用的是Windows)。 检查node-sass释放。 (这是你应该在node-sass版本中看到的。)

希望这对你有所帮助,抱歉我的英语不好:)

我们在2021年设置一个新的TeamCity构建代理时遇到了这个问题。最初我们使用Chocolatey安装了nodejs。我们重新安装回到原来的安装节点-v12.12.0-x64.msi。安装程序对话框中的第三个屏幕提供了安装编译本机模块所需的工具:

这样做之后,我们的问题就解决了。

Node-sass在安装时尝试为平台下载二进制文件。节点5由3.8 https://github.com/sass/node-sass/releases/tag/v3.8.0支持 如果你的Jenkins无法下载预构建的二进制文件,那么你需要遵循Node-gyp README上的平台要求(Python2, VS或MSBuild,…) 如果可能的话,我建议将Node更新到至少6,因为Node不再支持5了。 如果你想升级到8,你需要将node-sass更新到4.5.3