突然在我的一个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

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


当前回答

如果节点版本更新,NPM -g将工作。我遇到了这个问题,npm install -g——production windows-build-tools作为临时解决方案。但是从长期来看,升级Node.js、NPM和相关的包版本是一个更好的选择。

其他回答

在我的情况下,我有节点版本v16安装在机器上,但react项目使用node-sass版本v4.x。x,更新包。node-sass版本到v6.0.1的Json解决了这个问题, Node -sass的节点版本支持可以从NPM官方页面:https://www.npmjs.com/package/node-sass查看

使用npm 6.14.12降级到节点10.24.1版本对我来说是可行的。 随着安装windows-build-tools使用

NPM I -g windows build-tools

两种方案(2021年12月):

1 -你不能升级“node-sass”包! 安装python2并修改其.exe文件名。 修复PATH env变量记录顺序(详细信息如下)。 2 -更新node-sass包。

先决条件

您将Node.JS更新到Windows 10上的最新版本(v16.13.1)。 你在你的项目文件夹中运行yarn install或npm install,并收到一个错误(见下文)。

选项1。安装Python-2并修复PATH环境

参见MSI安装程序

安装后

注意!如果在x64上出现以下错误,请尝试从x64重新安装最新的Node.js到x86。(但在x86上,你也可能会收到内存限制错误。)

Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)

在PATH env变量中使用Python

Python 3的记录必须高于Python 2的记录!

将python.exe拷贝到python2.exe

第二个选项。升级node-sass包

在包中。json文件

修改方案。在你的项目文件夹上运行yarn install或NPM install。 其他文件将自动更新。

之前

在更新:

或者使用yarn或npm CLI来做同样的事情,但这可能会显著改变你的.lock文件。

更新后,你可能会意识到你还需要更新sass-loader, webpack等。

你可能遇到的错误(供参考)

gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2

gyp ERR! stack Error: Command failed: C:\Python310\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: Missing parentheses in call to 'print'. Did you mean print(...)?

Python2维护状态为“生命结束”,因此在新的ubuntu版本中默认不会安装。

安装最新的python2.7对我来说效果很好。

以下是安装说明:

下载python2.7: https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz 从下载的。tgz安装:

tar -xf Python-2.7.18.tgz
cd Python-2.7.18
./configure --enable-optimizations
sudo make altinstall

打开一个新终端并再次尝试npm安装

这是两年前的,但没有一个能帮到我。

我卸载了我的NodeJS v12.8.1 (Current),并安装了一个全新的v10.16.3 (LTS),我的ng build——prod工作了。