Suddenly in one of my jenkins environment build has started failing, while in local machine it seems to be working fine as i have python installed,
From the logs i was able to detect that the problem is with internal dependency that is node-gyp v3.5.0 from node-sass v3.8.0 when i researched by visiting this about node-gyp and found the prerequisite that Python needs to be installed.
So my question is that what version of node-sass can i install to bypass this or is there a better solution as my build was running fine till this morning on the same environment.
Node v5.10.1
ERROR LOG
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
Any thoughts are much appreciated, Thanks.
31 Answers
so this happened to me on windows recently. I fix it by following the following steps using a PowerShell with admin privileges:
- delete
node_modulesfolder - running
npm install --global windows-build-toolswith administrative privilege. (in my case need restart - and restart without ask!!!) - reinstalling node modules or node-sass with
npm install
The error message means that it cannot locate your python executable or binary.
In many cases, it's installed at c:\python27.
if it's not installed yet, you can install it with npm install --global windows-build-tools, which will only work if it hasn't been installed yet.
Adding it to the environment variables does not always work. A better alternative, is to just set it in the npm config.
npm config set python "C:\Python27\python.exe"
You need to follow the below steps to fix the error:
1: DELETE node_modules
2: npm install node-sass@<version-as-per-below-table>
3. npm install
Every node-sass version corresponds to a specific Node.JS build.
Below is a quick guide for minimum and maximum support supported version of node-sass (Check updates to below table here) :
| NodeJS | Supported node-sass version | Node Module |
|---------|-----------------------------|-------------|
| 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 |
My machine is Windows 10, I've faced similar problems while tried to compile SASS using node-sass package. My node version is v10.16.3 and npm version is 6.9.0
The way that I resolved the problem:
- At first delete
package-lock.jsonfile andnode_modules/folder. - Open Windows PowerShell as Administrator.
- Run the command
npm i -g node-sass. - After that, go to the project folder and run
npm install - And finally, run the SASS compiling script, in my case, it is
npm run build:css
And it works!!
Node-sass tries to download the binary for you platform when installing. Node 5 is supported by 3.8 If your Jenkins can't download the prebuilt binary, then you need to follow the platform requirements on Node-gyp README (Python2, VS or MSBuild, ...) If possible I'd suggest updating your Node to at least 6 since 5 isn't supported by Node anymore. If you want to upgrade to 8, you'll need to update node-sass to 4.5.3
node-gyp requires old Python 2 - link
If you don't have it installed - check other answers about installing windows-build-tools.
If you are like me and have both old and new Python versions installed, chances are that node-gyp tries to use Python 3. And that results in the following SyntaxError: invalid syntax error.
I found an article about having two Python versions installed. And they recommend renaming Python 2.* executable to python2.exe - link.
So it looks like node-gyp is expecting to find old Python 2 executable renamed. Hence the error message:
...
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
...
Once I renamed C:\Python27\python.exe to C:\Python27\python2.exe it worked without errors.
Of course, both C:\Python27\ and C:\Python39\ have to be in PATH variable. And no need in setting old Python version in npm config. Your default Python still will be the new one.
I had to:
Delete node_modules
Uninstall/reinstall node
npm install node-sass@4.12.0
worked fine after forcing it to the right sass version, according to the version said to be working with the right node.
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
There was lots of other errors that seemed to be caused by the wrong sass version defined.
Two options (December 2021):
- 1 - If you can't upgrade the node-sass package!
- Install Python 2 and modify its
.exefile name. - Fix
PATHenv variable records order (details below).
- Install Python 2 and modify its
- 2 - Update node-sass package.