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

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


当前回答

去包装。Json和更改

"node-sass": "4.14.1",

with

"node-sass": "^7.0.1",

它为我工作之后,我可以运行NPM安装

换句话说,您需要使用支持最新python版本的最新包。

注意:Node Saas 7.0.1兼容"react-scripts": "5.0.0"如果你的包。Json有“react-scripts”:“4.0.0”,然后将其更改为

 "react-scripts": "5.0.0", 

其他回答

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安装

我不得不:

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定义版本引起的。

节点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版本中看到的。)

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

几天前我也遇到了同样的问题。相信我,他们不需要在你的项目或系统中安装或卸载其他依赖项。

我是如何解决这个问题的,让我分享一下我的经验。

请去包装。json文件 向下滚动到下面或搜索optionalDependencies Object 只需删除整个对象并保存文件 尝试NPM安装,它将工作

另一个可能的解决方案:

请检查你的包裹。如果node-sass元素存在于optionaldependencies Object中,那么你需要以这种方式运行npm命令npm install——no-optional或also

注意:此解决方案仅适用于Angular项目

在这里输入图像描述 请查看这个包的截图。json文件

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

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

做得很好。