突然在我的一个jenkins环境中,构建已经开始失败,而在本地机器上它似乎工作正常,因为我安装了python,
我从日志中发现,当我研究时,问题是来自 node-sass v3.8.0 的 node-gyp v3.5.0 的内部依赖性问题通过访问有关node-gyp的this,找到了需要安装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
非常感谢任何想法,谢谢。
答案 0 :(得分:32)
所以最近我在Windows上发生了这种情况。我通过使用具有管理员权限的PowerShell执行以下步骤来解决此问题:
npm install --global windows-build-tools
文件夹npm install
sprintf()
重新安装节点模块或node-sass 答案 1 :(得分:7)
Node-sass尝试在安装时为您的平台下载二进制文件。 3.8 https://github.com/sass/node-sass/releases/tag/v3.8.0支持节点5 如果您的Jenkins无法下载预构建的二进制文件,那么您需要遵循Node-gyp README(Python2,VS或MSBuild,...)上的平台要求 如果可能的话,我建议将节点更新到至少6,因为节点不再支持5节点。 如果要升级到8,则需要将node-sass更新为4.5.3
答案 2 :(得分:5)
我的答案可能并不适用于所有人。
节点版本:v10.16.0
NPM:6.9.0
使用node-sass和node-sass-middleware时遇到很多麻烦。它们是有趣的软件包,因为它们被广泛使用(每周下载数百万次),但是它们的githubs显示出有限的依赖性和覆盖范围。我正在更新一个正在使用的旧平台。
我最终要做的是:
1)手动Delete node_modules
2)手动Delete package-lock.json
3) sudo npm install node-sass --unsafe-perm=true --allow-root
4) sudo npm install node-sass-middleware --unsafe-perm=true --allow-root
我有以下帮助,谢谢!
Pre-built binaries not found for grpc@1.10.1 and node@10.9.0
Error: EACCES: permission denied when trying to install ESLint using npm
答案 3 :(得分:3)
今年2岁,但没有一个帮助我。
我卸载了NodeJS v12.8.1(当前)并安装了一个全新的v10.16.3(LTS),并且我的ng build --prod
工作正常。
答案 4 :(得分:3)
该错误消息表示无法找到您的python可执行文件或二进制文件。
在许多情况下,它安装在c:\ python27。
如果尚未安装,则可以使用npm install --global windows-build-tools
进行安装,只有在尚未安装的情况下,它才能工作。
将其添加到环境变量并不总是有效。 更好的替代方法是在npm配置中进行设置。
npm config set python c:\python27\python.exe
答案 5 :(得分:2)
我有 node 15.x.x
和 "node-sass": "^4.11.0"
。
我在 node-sass
的发行说明中看到,与 node-sass 4.11.0 兼容的节点最高版本是 11,所以我卸载了节点并重新安装了 11.15.0 版本(我正在使用 Windows)。
检查node-sass releases。
(this is what you should see in the node-sass releases.)
希望对我的英语有所帮助和抱歉:)
答案 6 :(得分:2)
node-gyp 需要旧的 Python 2 -link
如果尚未安装,请检查有关安装 windows-build-tools 的其他答案。
如果您和我一样,并且同时安装了旧的和新的Python版本,则node-gyp可能会尝试使用Python3。这将导致以下SyntaxError: invalid syntax
错误。
我找到了一篇有关安装两个Python版本的文章。他们建议将Python 2. *可执行文件重命名为python2.exe
-link。
所以看起来node-gyp希望找到已重命名的旧Python 2可执行文件。因此,错误消息:
...
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
...
将C:\Python27\python.exe
重命名为C:\Python27\python2.exe
后,它就可以正常工作了。
当然,C:\Python27\
和C:\Python39\
都必须在PATH变量中。无需在npm config中设置旧的Python版本。您的默认Python仍将是新的。
答案 7 :(得分:1)
在我的电脑上安装不同版本的python时遇到了同样的问题。只需将节点升级到最新版本v8.11.2和npm 5.6.0,然后安装node-sass@4.5.3之后就可以了。
答案 8 :(得分:1)
我几天前遇到了同样的问题。相信我,他们不需要在您的项目或系统中安装或卸载其他依赖项。
我是如何解决这个问题的,让我分享一下我的经验。
另一种可能的解决方案:
请检查您的 package.json 文件,如果 optionalDepedencies 对象中存在 node-sass 元素,那么您需要以这种方式运行 npm 命令npm install --no-optional
或者如果只是从 optionalDepedencies 对象
注意:此解决方案仅适用于 Angular 项目
enter image description here 请查看 package.json 文件的截图
答案 9 :(得分:1)
Python2 维护状态是“生命周期结束”,因此默认情况下它不会安装在新的 ubuntu 版本上。
安装最新的 python2.7 对我来说效果很好。
安装说明如下:
tar -xf Python-2.7.18.tgz
cd Python-2.7.18
./configure --enable-optimizations
sudo make altinstall
打开一个新终端并尝试输入 npm install
答案 10 :(得分:0)
我在Windows 10上发现了与 Node 12.19.0 和 yarn 1.22.5 相同的问题,我通过安装最新的稳定的python 64位来解决此问题。 python安装期间环境变量的路径。安装python之后,我为env vars重新启动了机器。
答案 11 :(得分:0)
嘿,请按照以下步骤解决此错误
c:\python27
答案 12 :(得分:0)
我的机器是 Windows 10 ,在尝试使用node-sass
软件包编译 SASS 时,我遇到了类似的问题。我的节点版本为 v10.16.3 ,npm版本为 6.9.0
我解决问题的方式:
package-lock.json
文件和node_modules/
文件夹。npm i -g node-sass
。npm install
npm run build:css
它有效!!
答案 13 :(得分:0)
对于yarn项目,使用“yarn install --ignore-engines”忽略节点版本将安装任何node-sass v.而不会出现这些python错误
答案 14 :(得分:0)
查看所有答案后,我注意到此解决方案可能非常有帮助。它在安装node-sass时说明了how to configure "npm" to find your installed python version。请记住,node-sass需要使用node-gyp(一个npm构建工具)来查找您的python路径。或者只是安装python,然后按照给出的相同解决方案进行操作(在链接中)。谢谢。
答案 15 :(得分:0)
以下是在运行基于旧 Error: not found: python2
的项目时帮助我防止错误 node-gyp v3.8.0
的方法。
npm install --global --production windows-build-tools@4.0.0
python.exe
中的 python2.exe
重命名为 %USERPROFILE%\.windows-build-tools\python27
%USERPROFILE%\.windows-build-tools\python27
是您的 PATH
环境变量的一部分(这是 windows-build-tools
应该已经为您做的)npm
将 VS 2017 与 npm config set msvs_version 2017
一起使用node-gyp
的脚本(node-gyp
现在会找到 python2.exe
)您也可以尝试升级您的项目以使用 node-gyp v8.0.0 而不是 node-gyp v3.8.0。在这种情况下,请将以下 resolution
条目添加到您的 package.json
:
"resolutions": {
"node-gyp": "8.0.0"
}
之后,请确保您已安装 Python 3 和 Visual Studio 2017 构建工具和/或 Visual Studio 2019 构建工具。您还可以运行 npm config delete msvs_version
让 node-gyp
自动检测您的 VS 版本。
测试:
答案 16 :(得分:0)
你也可以尝试使用 sass 模块代替 node-sass:
npm install sass
答案 17 :(得分:0)
如果您使用的是 Visual Studio。请按照以下步骤操作:
npm cache clean --force
npm config set msvs_version 2019 --global
npm install node-sass
答案 18 :(得分:0)
我必须:
Delete node_modules
Uninstall/reinstall node
npm install node-sass@4.12.0
根据据说适用于正确节点的版本,在将其强制为正确的sass版本后,工作正常。
NodeJS Minimum node-sass version Node Module
Node 12 4.12+ 72
Node 11 4.10+ 67
Node 10 4.9+ 64
Node 8 4.5.3+ 57
还有许多其他错误,似乎是由于定义了错误的sass版本引起的。
答案 19 :(得分:0)