Vip*_*nth 30 node.js node-gyp node-sass
突然在我的一个jenkins环境中构建已经开始失败,而在本地机器上它似乎工作正常,因为我安装了python,
从日志中我能够检测到问题是内部依赖,即来自node-sass v3.8.0的node-gyp v3.5.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
Run Code Online (Sandbox Code Playgroud)
任何想法都非常感谢,谢谢.
Gop*_*hra 133
您需要按照以下步骤修复该错误:
1: DELETE node_modules
2: npm install node-sass@<version-as-per-below-table>
3. npm install
Run Code Online (Sandbox Code Playgroud)
每个node-sass版本都对应于特定的 Node.JS 版本。
下面是 Node-sass 的最小和最大支持版本的快速指南(在此处检查下表的更新):
| NodeJS | Supported node-sass version | Node Module |
|---------|-----------------------------|-------------|
| Node 20 | 9.0+ | 115 |
| Node 19 | 8.0+ | 111 |
| Node 18 | 8.0+ | 108 |
| Node 17 | 7.0+, <8.0 | 102 |
| Node 16 | 6.0+ | 93 |
| Node 15 | 5.0+ | 88 |
| Node 14 | 4.14+ | 83 |
| Node 13 | 4.13+, <5.0 | 79 |
| Node 12 | 4.12+ | 72 |
| Node 11 | 4.10+, <5.0 | 67 |
| Node 10 | 4.9+, <6.0 | 64 |
| Node 8 | 4.5.3+, <5.0 | 57 |
| Node <8 | <5.0 | <57 |
Run Code Online (Sandbox Code Playgroud)
She*_*azi 49
所以这似乎最近在Windows上对我说.我通过使用具有管理员权限的PowerShell执行以下步骤来修复它:
node_modules
文件夹npm install --global windows-build-tools
npm install
bvd*_*vdb 47
该错误消息意味着它无法找到您的 python 可执行文件或二进制文件。
在许多情况下,它安装在 c:\python27。如果尚未安装,您可以使用 安装它npm install --global windows-build-tools
,这仅在尚未安装时才有效。
将它添加到环境变量并不总是有效。更好的选择是在 npm 配置中设置它。
npm config set python c:\python27\python.exe
it3*_*3xl 45
.exe
文件名。PATH
环境变量记录顺序(详细信息如下)。您在 Windows 10 上将 Node.JS 更新到最新版本 (v16.13.1)。您在项目文件夹中
运行yarn install
或并收到错误(如下所示)。npm install
PATH
环境笔记!如果您在 x64 上收到以下错误,请尝试将最新的 Node.js 从 x64 重新安装到 x86。(但是对于 x86,您也可能会收到内存限制错误。)
Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)
Run Code Online (Sandbox Code Playgroud)
PATH
环境变量中的Resort Python记录Python 3 记录必须高于 Python 2 记录!
python.exe
到python2.exe
node-sass
包package.json
档修改package.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(...)?
Run Code Online (Sandbox Code Playgroud)
Has*_*eed 31
转到 package.json 并更改
"node-sass": "4.14.1",
Run Code Online (Sandbox Code Playgroud)
和
"node-sass": "^7.0.1",
Run Code Online (Sandbox Code Playgroud)
之后它对我有用,我可以运行 npm install
换句话说,你需要使用最新的包来支持最新的Python版本。
注意: Node Saas 7.0.1 兼容 "react-scripts": "5.0.0" 如果你的 package.json 中有 "react-scripts": "4.0.0",则将其更改为
"react-scripts": "5.0.0",
Run Code Online (Sandbox Code Playgroud)
Fat*_*ora 26
我的机器是Windows 10,我在尝试使用package.json编译SASS时遇到了类似的问题node-sass
。我的 node 版本是v10.16.3,npm 版本是6.9.0
我解决问题的方法:
package-lock.json
文件和node_modules/
文件夹。npm i -g node-sass
。npm install
npm run build:css
它有效!!
小智 20
节点 sass已弃用
\n无需费力安装旧版本的 Python,只需迁移到dart.sass
\n对于我的 ReactJS 项目 (npm),以下步骤对我有用:
\n从项目中删除node_modules
\n在 package.json 中,删除此\n依赖项:
\n"dependencies": {\n \xe2\x80\xa6,\n "node-sass": "^3.0.0",\n \xe2\x80\xa6\n}\n
Run Code Online (Sandbox Code Playgroud)\nnpm install --save-dev sass
npm install
现在尝试使用运行您的项目npm start
如果您收到类似“要导入 Sass 文件,您首先需要安装 node-sass”的错误,请按照此处所述运行此命令:
\nnpm install node-sass@npm:sass
如果您使用的是纱线,请执行等效命令,但在最后一步执行此操作,如下所述: \
nyarn remove node-sass
\nyarn add sass
Ste*_*mes 16
我不得不:
Delete node_modules
Uninstall/reinstall node
npm install node-sass@4.12.0
Run Code Online (Sandbox Code Playgroud)
根据据说与正确节点一起工作的版本,在将其强制为正确的 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
Run Code Online (Sandbox Code Playgroud)
还有许多其他错误似乎是由定义的错误 sass 版本引起的。
小智 14
node-gyp需要旧的Python 2 -链接
如果您没有安装它 - 检查有关安装windows-build-tools 的其他答案。
如果您像我一样安装了新旧 Python 版本,那么 node-gyp 可能会尝试使用 Python 3。这会导致以下SyntaxError: invalid syntax
错误。
我找到了一篇关于安装两个 Python 版本的文章。他们建议改名的Python 2 *可执行文件python2.exe
-链接。
所以看起来 node-gyp 希望找到重命名的旧 Python 2 可执行文件。因此错误消息:
...
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
...
Run Code Online (Sandbox Code Playgroud)
一旦我重命名C:\Python27\python.exe
,C:\Python27\python2.exe
它就可以正常工作。
当然,无论是C:\Python27\
和C:\Python39\
必须在PATH变量。并且不需要在 npm config 中设置旧的 Python 版本。你的默认 Python 仍然是新的。
Node-sass尝试在安装时为您的平台下载二进制文件.节点5由3.8 https://github.com/sass/node-sass/releases/tag/v3.8.0支持 如果您的Jenkins无法下载预构建的二进制文件,那么您需要遵循Node-gyp的平台要求自述文件(Python2,VS或MSBuild,...)如果可能,我建议将节点更新到至少6,因为节点不再支持5.如果要升级到8,则需要将node-sass更新为4.5.3
我使用的是 Windows 11 计算机,为了修复它,我使用以下链接自行下载了 python27: https: //www.python.org/download/releases/2.7/。
安装后我运行了这个命令:
npm config set python c:\python27\python.exe
Run Code Online (Sandbox Code Playgroud)
在 2022 年为我工作,实际上我们可以通过安装 python 2.7npm
安装后python 2.7
,我们可以强制运行npm install
使用python 2.7
萨斯
npm install --global windows-build-tools --save
npm install --python=python2.7
我的回答可能不适用于所有人。
节点版本:v10.16.0
NPM:6.9.0
我在使用node-sass和node-sass-middleware 时遇到了很多麻烦。它们是有趣的包,因为它们被广泛使用(每周下载数百万次),但它们的 github 显示出有限的依赖性和覆盖范围。我正在更新我一直在使用的旧平台。
我最终不得不做的是:
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
我得到了以下帮助,谢谢!
未找到 grpc@1.10.1 和 node@10.9.0 的预构建二进制文件
错误:EACCES:尝试使用 npm 安装 ESLint 时权限被拒绝
小智 5
我有node 15.x.x
,并且"node-sass": "^4.11.0"
。我在发行说明中node-sass
看到与node-sass 4.11.0兼容的node最高版本是11,所以我卸载了node并重新安装了11.15.0版本(我正在使用Windows)。检查node-sass 版本。
(这是您应该在 node-sass 版本中看到的内容。)
希望对我有帮助,对我的英语感到抱歉:)
以下是帮助我Error: not found: python2
在运行基于旧node-gyp v3.8.0
.
npm install --global --production windows-build-tools@4.0.0
python.exe
为python2.exe
in%USERPROFILE%\.windows-build-tools\python27
%USERPROFILE%\.windows-build-tools\python27
是您的环境变量的一部分PATH
(这是windows-build-tools
应该已经为您做的事情)npm
使用 VS 2017npm 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"
}
Run Code Online (Sandbox Code Playgroud)
然后,确保安装了Python 3和Visual Studio 2017 Build Tools和/或Visual Studio 2019 Build Tools。你也可以运行npm config delete msvs_version
让node-gyp
自动检测你的VS版本。
测试用:
归档时间: |
|
查看次数: |
49533 次 |
最近记录: |