417

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.

Vipul Panth
  • 5,221
  • 4
  • 16
  • 27
  • 3
    You want to install angular, so you also want the angular-cli tools, then you need python2 and on windows, you also need msbuild.exe which comes with visualstudio2017. So, you first need to install the visual studio installer tool. Then you have so much tools installed, that you need to configure the versions of your tools in npm. – bvdb Apr 08 '21 at 06:51
  • Sorry , for the late reply, but this was for react js. – Vipul Panth Jan 13 '22 at 04:36

37 Answers37

374

so this happened to me on windows recently. I fix it by following the following steps using a PowerShell with admin privileges:

  1. delete node_modulesfolder
  2. running npm install --global windows-build-tools with administrative privilege. (in my case need restart - and restart without ask!!!)
  3. reinstalling node modules or node-sass with npm install
saber tabatabaee yazdi
  • 4,404
  • 3
  • 42
  • 58
Shezan Kazi
  • 4,471
  • 3
  • 14
  • 27
  • 75
    This is exactly the right answer. `npm install --global windows-build-tools` installs Python 2.7, and installs it globally (so you don't have to re-install on a per-project basis). It fixes the "can't install SASS" problem. NOTE: On windows, you must run your npm command prompt as "Administrator". – paulsm4 Nov 22 '18 at 22:14
  • 1
    It worked for me, windows 10, node v10.15.0, npm 6.7.0 – Tasnim Reza Apr 04 '19 at 08:37
  • 18
    I had to delete the `package-lock.json` as well to make it work. – ush189 Apr 21 '19 at 16:44
  • This worked for me, but then deleted the MSBuild tools from the Visual Studio folder, I had to re-install those subsequently. – uniquelau May 01 '19 at 08:25
  • To those who are stuck on installing BuildTools, you may execute the commands in PowerShell and run as Administrator – user1441797 Aug 11 '20 at 10:36
  • This along with @bvdb 's answer helped me. Had to set the python in npm config – RBz Jan 17 '21 at 11:51
  • 50
    If you try this answer and it freezes-up when running `npm`, try it with `windows-build-tools` `v4`: `npm install --global --production windows-build-tools@4.0.0`, as described [here](https://github.com/felixrieseberg/windows-build-tools/issues/172#issuecomment-484091133). – Cato Minor Mar 18 '21 at 15:26
  • 2
    This worked for me, but I also had to update my version of `node-sass` to `5.0.0` – Adam Nellis Apr 06 '21 at 10:16
  • 1
    *If you try this answer and it freezes-up when running* I used the choclatey installer instead as [documented here](https://github.com/felixrieseberg/windows-build-tools/issues/172#issuecomment-824916268). Didn't freeze up then – Liam Jun 08 '21 at 08:28
  • 1
    I had to uninstall an existing python2.7 that I installed using scoop. It expects the python to be in `c:\python27` directory. – h-rai Jul 07 '21 at 09:09
  • As stated here https://github.com/felixrieseberg/windows-build-tools/issues/179 using `npm install --global windows-build-tools@4.0.0` should help anybody whos installer isn't completing. – Squirrel in training Oct 18 '21 at 09:16
  • 1
    So how it gonna works on other operation systems? is it working also on MacOS or Linux Ubuntu? I think that old version of node-sass is not compatible with new version of Nodejs. – Ali SadeghipourKorabaslo Nov 10 '21 at 16:21
  • 55
    What if I'm on macOS?? – Andor Németh May 09 '22 at 07:14
  • if stuck/freezed, you might consider this thread (download npm and use installer for that) on windows https://stackoverflow.com/questions/70902056/installing-global-windows-build-tools-never-completes – Pipo Nov 25 '22 at 11:34
  • 1
    I for a moment was frustrated as it didn't work. But realized I didn't restart the system, and voila! It worked after the RESTART! – Mohammad Rayan Dec 20 '22 at 12:03
  • I had to do this first: https://stackoverflow.com/questions/74227892/error-typeerror-process-env-only-accepts-a-configurable-whileinstall-windows then after windows restart : npm i node-sass@latest – AndyNope Feb 16 '23 at 10:24
  • "npm ERR! Downloading installers failed. Error: TypeError: 'process.env' only accepts a configurable, writable, and enumerable data descriptor". From one error to another :| – Enrico Aug 27 '23 at 08:57
151

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"

silkfire
  • 24,585
  • 15
  • 82
  • 105
bvdb
  • 22,839
  • 10
  • 110
  • 123
110

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 versions of node-sass (Check updates to the below table here) :


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

Gopal Mishra
  • 1,575
  • 1
  • 14
  • 17
  • Adjusting the version number solved the problem after running `npm install` – user3072843 Sep 22 '21 at 15:11
  • 9
    you shouldn'T recommend node-sass at all. It's deprecated. The way to go nowadays is with the dart sass compiler (npm 'sass' module) – leachim Oct 06 '21 at 16:40
  • You are genius! I forgot to check node-sass version in my package.json. For everyone else there whose still struggling - check all your versions! In my case node v16.13, python 3.10, node-gyp 8.3 was installed, but I forgot to change version of node-sass to 6.0.1. – Vladimir Titkov Nov 11 '21 at 10:39
  • for me this error disappeared after replacing the version of the node from 16 to 14. – Xth Nov 17 '21 at 10:31
  • Thanks, I was running Node 16 LTS, but after I changed to 14 LTS, it worked like a charm. – jvbs Dec 30 '21 at 13:31
  • 5
    This was extremely helpful. Of course updating dependencies is always preferred, but sometimes in a pinch this is not possible. This table allowed me to identify the appropriate node version, then use `nvm` to downgrade to that version to get up and running in the short term. (On Fedora Linux 35 Workstation, for what it is worth) – Alexander Nied Mar 12 '22 at 20:26
  • If you find `npm` compatibility issue with the version of node that you already have, [**That Answer**](https://askubuntu.com/a/1382566/217641) on Ask Ubuntu should help. – SaidbakR Apr 30 '22 at 00:24
  • This answer helped me to fix the issue. Thanks!!! – DevThiman Aug 17 '22 at 07:41
  • Best Answer I found all day, but I get `Starting 'style'... Error in plugin "gulp-sass" Message: gulp-sass no longer has a default Sass compiler; please set one yourself. Both the "sass" and "node-sass" packages are permitted. For example, in your gulpfile: const sass = require('gulp-sass')(require('sass'));` now , which makes me think would need to make changes to the code right? – Lucifer Jul 24 '23 at 08:14
  • Lucifer, yes you are correct. This is what I found on SO: [QUESTION](https://stackoverflow.com/questions/68417640/gulp-sass-5-does-not-have-a-default-sass-compiler-please-set-one-yourself) – Gopal Mishra Jul 24 '23 at 11:13
41

Two options (December 2021):

  • 1 - You can't upgrade "node-sass" package!
    • Install Python 2 and modify its .exe file name.
    • Fix PATH env variable records order (details below).
  • 2 - Update node-sass package.

Precondition

You updated Node.JS to the latest version (v16.13.1) on Windows 10.
You run yarn install or npm install in your project's folder and receive an error (look below).

Option 1. Installing of Python-2 and fixing PATH env

Latest Python 2 version

See MSI installer enter image description here

After installation Python installations

Note! Try to reinstall the latest Node.js to x86 from x64, if you get the following error on x64. (But with x86 you could receive memory limit errors, also.)

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

Resort Python records in PATH env variable

Python 3 records must be above Python 2 records!

PATH environment variable editing

Sorting of Python records in PATH environment variable

Copy python.exe to python2.exe

Renaming of python.exe to python2.exe

Option 2. Upgrading of node-sass package

Over package.json file

Modify package.json and run yarn install or npm install on your project's folder.
Other files will be updated automatically.

Before befor updating before updating in package.json

After updating: After updating

Or use yarn or npm CLI to do the same but it may noticeably change your .lock files.

After updating you could realize that you need to update also sass-loader, webpack, etc.

Error you may have (FYI)

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(...)?
it3xl
  • 2,372
  • 27
  • 37
  • Thanks this worked! But additionally I copied "python.exe" to "python2.exe", so python2 is in search path. – Aleksey Kuznetsov Dec 21 '21 at 22:22
  • I have this exact issue you have mentioned as FYI, but I'm on macOS, what should I do? – rasitayaz Apr 23 '23 at 11:36
  • @rasitayaz, sorry. You have to investigate it or create a new SO-question. IMHO, try to use Python2 with Python3 on the same Mac. I'm also on macOS but kinda in "another universe" right now. – it3xl Apr 25 '23 at 20:20
38

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:

  1. At first delete package-lock.json file and node_modules/ folder.
  2. Open Windows PowerShell as Administrator.
  3. Run the command npm i -g node-sass.
  4. After that, go to the project folder and run npm install
  5. And finally, run the SASS compiling script, in my case, it is npm run build:css

And it works!!

Fatema Tuz Zuhora
  • 3,088
  • 1
  • 21
  • 33
35

Node-sass tries to download the binary for you platform when installing. Node 5 is supported by 3.8 https://github.com/sass/node-sass/releases/tag/v3.8.0 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

nschonni
  • 4,069
  • 1
  • 28
  • 37
  • 1
    Thank you so much for your efforts, i was able to find the issue that node-sass package was missing from the node-modules, checked and found that indeed version is an issue, but my one was due to connection timeout, reset-cache and it seems to be working fine for now, but yes will update node according to your fix. – Vipul Panth Aug 22 '17 at 09:14
  • 1
    @nschonni I'm also facing the same error. The node version is 7.7.1 and npm is 4.1.2. Can you please help me with this. – Tanvi Garg Jan 29 '18 at 08:15
  • Same issue for Node (10.4.0), npm (6.1.0), node-sass (4.9.0) – Saravanan Sachi Jul 01 '18 at 06:26
  • Does this mean I need to downgrade my node? I've got node 12, and need to install node-sass 4.13. – mcv Feb 25 '20 at 16:30
  • No, Node 12 is compatible with 4.13 – nschonni Feb 25 '20 at 16:31
  • Weird. I'm getting these same errors. And @Shezan Kazi's solution below mysteriously doesn't work for me because the admin rights I'm supposed to have on this machine apparently don't work. – mcv Feb 25 '20 at 16:33
  • Thanks your comment was very useful, in my case (Manjaro) I had to install Python2 on my machine. and that fixed everything. – Kay Feb 13 '21 at 11:02
  • now *node-sass* version is *6.0.0*. That was the only fix needed in my case (+regenerate yarn.lock). – pdem Jun 09 '21 at 13:35
25

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.

Stephen Himes
  • 655
  • 9
  • 13
  • 1
    Thank you! This was it for me, a colleague was using an older node version, I was using 12, so it required different versions of node-sass. I updated node-sass to 4.12 and forced my colleague to upgrade to node 12 and everything was good! – Jason Masters Sep 24 '19 at 21:29
  • 1
    This pretty much sums up the problem. Node-sass versions are compatible with specific versions of nodejs. This really should have a major version bump to illustrate this. Anything lower than 4.12 won't work with node 12.14 – Robharrisaz Jan 10 '20 at 19:58
  • 1
    And no version is working with [node 14 on Windows x64](https://github.com/sass/node-sass/issues/2895) now. I have to downgrade to node 12 to make it work. – bonniss Apr 25 '20 at 04:54
  • 2
    Just an update: Check compatibility here: https://www.npmjs.com/package/node-sass and install node-sass as per ur node version. Also if the problem persists run `npm rebuild node-sass`. – Gopal Mishra Sep 09 '21 at 14:30
25

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.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Konstantin Lyakh
  • 781
  • 6
  • 15
  • @RohanDevaki Your answer is totally different because you suggest removing Python 3. While my suggestion is to leave both Python versions installed and just rename Python 2 executable. – Konstantin Lyakh Nov 05 '20 at 12:21
  • @ford04 "Python", "error message", etc aren't code. You should have rejected that edit. See https://meta.stackoverflow.com/q/360491/4284627. – Donald Duck Nov 15 '20 at 11:11
  • tried everything above, just renaming python.exe to python2.exe solved it (python path was in environment variable). now, npm install worked, thks – Ramon Veloso Oct 13 '22 at 20:24
25

go to package.json and change

"node-sass": "4.14.1",

with

"node-sass": "^7.0.1",

it works for me after that i can able to run npm install

in other word you need to use the latest package which can support the latest python version.

Note: Node Saas 7.0.1 is compatible with "react-scripts": "5.0.0" if your package.json has "react-scripts": "4.0.0", then change it as

 "react-scripts": "5.0.0", 
Hassan Saeed
  • 6,326
  • 1
  • 39
  • 37
19

node-sass is deprecated as of October 26th, 2020

No need to mess around with installing old versions of Python, just migrate to dart.sass

For my ReactJS project (npm), the following steps worked for me:

  1. Delete node_modules from the project

  2. In package.json, remove this dependency:

    "dependencies": {
        …,
        "node-sass": "^3.0.0",
        …
    }
    
  3. npm install --save-dev sass

  4. npm install

  5. Now try running your project using npm start

  6. If you receive an error like "To import Sass files, you first need to install node-sass", run this command as described here:
    npm install node-sass@npm:sass

If you're using yarn, do the equivalent commands but on the last step do this instead, as described here:
yarn remove node-sass
yarn add sass


Alex Ertl
  • 358
  • 3
  • 7
7

My answer might not apply to everyone. Node version: v10.16.0 NPM: 6.9.0

I was having a lot of trouble using node-sass and node-sass-middleware. They are interesting packages because they are widely used (millions of downloads weekly), but their githubs show a limited dependencies and coverage. I was updating an older platform I'd been working on.

What I ended up having to do was:

1) Manually Delete node_modules

2) Manually 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

I had the following help, thanks!

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

maudulus
  • 10,627
  • 10
  • 78
  • 117
7

I'm on a Windows 11 machine, and to fix it I downloaded python27 myself, using this link: https://www.python.org/download/releases/2.7/.

And after installed I ran this command:

npm config set python c:\python27\python.exe
Tiago Ávila
  • 2,737
  • 1
  • 31
  • 34
6

Hey I got this error resolved by following the steps

  • first I uninstalled python 3.8.6 (latest version)
  • then I installed python 2.7.1 (any Python 2 version will work, but not much older and this is recommended)
  • then I added c:\python27 to environment variables
  • my OS is windows, so I followed this link
  • It worked
Rohan Devaki
  • 2,931
  • 1
  • 14
  • 22
6

Worked for me in 2022, actually we can install python 2.7 through npm After the installation for python 2.7, we can force to run npm install with using python 2.7

Sass

  1. npm install --global windows-build-tools --save
  2. npm install --python=python2.7
W Kenny
  • 1,855
  • 22
  • 33
5

This is 2 years old, but none of them helped me.

I uninstalled my NodeJS v12.8.1 (Current) and installed a brand new v10.16.3 (LTS) and my ng build --prod worked.

Bruno Miquelin
  • 651
  • 1
  • 8
  • 22
5

I had node 15.x.x , and "node-sass": "^4.11.0". I saw in the release notes from node-sass and saw the node higest version compatible with node-sass 4.11.0 was 11, so I uninstalled node and reinstall 11.15.0 version (I'm working with Windows). Check node-sass releases. (this is what you should see in the node-sass releases.)

Hope that helps and sorry for my english :)

  • Thanks much, switching to node 11.15.0 it worked. Additional to this I had uninstalled my python version 3 and switched to python 2. Not sure if both caused it to work out – techloris_109 Mar 04 '21 at 14:53
  • This was the solution for me, thank you! (I use nvm so I just switched to an older version of node) – Fredrik Stolpe Sep 15 '21 at 12:55
4

Here is what helped me to prevent the error Error: not found: python2 when running a project based on the old node-gyp v3.8.0.

  1. Run npm install --global --production windows-build-tools@4.0.0
  2. Rename python.exe to python2.exe in %USERPROFILE%\.windows-build-tools\python27
  3. Make sure that %USERPROFILE%\.windows-build-tools\python27 is part of your PATH environment variable (this is what windows-build-tools should already do for you)
  4. Download Visual Studio 2017 Build Tools
  5. Tell npm to use VS 2017 with npm config set msvs_version 2017
  6. Run the script which uses node-gyp (node-gyp will now find python2.exe)

Alternative: Force upgrade of node-gyp

You can also try to upgrade your project to use node-gyp v8.0.0 instead of node-gyp v3.8.0. In this case, add the following resolution entry to your package.json:

  "resolutions": {
    "node-gyp": "8.0.0"
  }

Afterwards, make sure that you have Python 3 installed and Visual Studio 2017 Build Tools and/or Visual Studio 2019 Build Tools. You can also run npm config delete msvs_version to let node-gyp automatically detect your VS version.

Tested with:

  • Windows 10 Pro Build 19042.985
  • Node.js v15.14.0
  • npm v7.7.6
  • node-gyp -v v3.8.0.
Benny Code
  • 51,456
  • 28
  • 233
  • 198
  • 1
    You, sir, deserve a medal. Thanks for the "resolutions" part. It works. I think that node-sass has and old dependency of node-gyp referenced inside, trying to install an obsolete version. – Tiberiu Mihai May 03 '22 at 07:55
3

had the same issue lost hours trying to install different version of python on my PC. Simply Upgrade node to the latest version v8.11.2 and npm 5.6.0, then after install node-sass@4.5.3 and you'll be fine.

davyCode
  • 399
  • 4
  • 4
  • 1
    This worked for me, I've been looking for hours for this! As a tip: using NVM really helps if you want to handle multiple versions of Node.js. – j3ff Aug 07 '19 at 14:18
3

We encountered this problem in 2021 when setting up a new TeamCity build agent. Originally we had installed nodejs using Chocolatey. We reinstalled going back to the original installer node-v12.12.0-x64.msi. The third screen in the installer dialog offers to install the tools necessary to compile native modules:

enter image description here

After doing this our problem was gone.

Ross Presser
  • 6,027
  • 1
  • 34
  • 66
2

After looking at all the answers, i notice this solution might be very helpful. It explains how to configure "npm" to find your installed python version while installing node-sass. Remember, node-sass requires node-gyp (an npm build-tool) which looks for your python path. Or just install python, and follow the same solution given (in the link). Thanks.

MwamiTovi
  • 2,425
  • 17
  • 25
2

In case of yarn projects, ignoring the node version with "yarn install --ignore-engines" will install any node-sass v. without these python errors

Rege
  • 41
  • 3
2

Python2 maintenance status is "end of life" so it not installed by default on new ubuntu releases.

Installing the latest python2.7 worked fine for me.

Here is the instructions to install it:

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

Open a new terminal and try agin the npm install

1

I found the same issue with Node 12.19.0 and yarn 1.22.5 on Windows 10. I fixed the problem by installing latest stable python 64-bit with adding the path to Environment Variables during python installation. After python installation, I restarted my machine for env vars.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
DevLoverUmar
  • 11,809
  • 11
  • 68
  • 98
  • @RohanDevaki It seems like you've been suggesting a lot of edits formatting random keywords as code. Please stop. For example "Windows 10", "Node 12.19.0", "Python 64-bit", etc aren't code and shouldn't be formatted as such. See [this post](https://meta.stackoverflow.com/a/360495/4284627) by a moderator. – Donald Duck Nov 15 '20 at 11:20
1

I am using Windows 11 and I had tried using npm i -g windows-build-tools but it stuck forever. So, what worked for me was:

  1. Install Visual Studio Build tools 2017 from here.
  2. After installing, open Powershell as admin.
  3. Enter this command: npm install --global --production windows-build-tools --vs2015
  4. Thank me later!

It fixed all errors related to build tools for me on Windows 11.

hd3adcode
  • 354
  • 5
  • 12
1

In my case, i had node version v16 installed in the machine, but the react project used node-sass version v4.x.x, Updating the package.json with node-sass version to v6.0.1 solved the issue,
node version support for node-sass can be checked from official npm page: https://www.npmjs.com/package/node-sass

Kritish Bhattarai
  • 1,501
  • 15
  • 20
1

A simple solution for windows 11 machines is,

  • Delete package-lock.json file and node_modules/ folder.
  • Open Windows Terminal as Administrator.
  • Run the command npm i -g node-sass.
  • Go to the project folder and run npm install
  • Now run the project with npm start
Lokesh
  • 209
  • 4
  • 2
1

Got this error on Windows 11 with latest Node.js LTS Version: 18.13.0 (includes npm 8.19.3)

https://nodejs.org/en/download/

Fixed by first downloading Python 2.7.18 manually since only Python 3.11 was installed.

https://www.python.org/downloads/windows/

https://www.python.org/downloads/release/python-2718/

After install I ran the command from @bvdb:

npm config set python "C:\Python27\python.exe"

Source:

https://stackoverflow.com/a/64486670/3850405

This fixed the error

Ogglas
  • 62,132
  • 37
  • 328
  • 418
0

also you can try to use sass module instead of node-sass:

npm install sass
Ivan Bryzzhin
  • 2,009
  • 21
  • 27
0

If you are using Visual Studio. follow these steps:

npm cache clean --force
npm config set msvs_version 2019 --global
npm install node-sass
SharpCoder
  • 18,279
  • 43
  • 153
  • 249
0

This same issue I faced few days ago. Believe on me their is no need to install or uninstall other dependencies in your project or system.

How had I resolve this issue let me share my experience.

  • Please go to package.json file
  • Scroll down all the way below or search for optionalDependencies Object
  • Just remove this whole object & save the file
  • try npm install, it will work

Another Possible Solution:

Please check your package.json file if node-sass element is exist inside the optionalDepedencies Object then you need to run npm command in this way npm install --no-optional or also If just remove node-sass element from optionalDepedencies Object

Note: this solution is only for Angular Project

enter image description here Please Check out this screenshot of package.json file

Suneel Kumar
  • 756
  • 2
  • 5
  • 11
0

Downgrading to node 10.24.1 version with npm 6.14.12 worked for me. Along with installing windows-build-tools using

npm i -g windows-build-tools

Rahul
  • 11
  • 1
0

npm i npm -g will work if node version is updated. I ran into this issue, and npm install -g --production windows-build-tools worked as interim solution. But upgrading Node.js, NPM, and associated package versions is a better long term option.

Codeip
  • 31
  • 2
0

My OS is Win 10 x64. The similar issue found while doing npm install.

  1. Check that the node version suits the node-sass version.(Refer to the above tables.) Upgrade or downgrade node version, if needed

  2. Delete node_modules folder

    $ npm install node-sass@

    $ npm install

Well done.

0

None of the above answers solved my problem, it was way simpler than i tought.

Simply downgrade your node version to match the node-sass version:

nvm list
nvm user <node-version>
PedroMiotti
  • 995
  • 10
  • 13
0

Stuck through the same issue but nothing seemed to be working with me, unless I tried installing node-sass again on my global node modules config

npm install -g node-sass@6

This worked like a charm

0

node-sass deprecated now. we need to use sass instead of node-sass. as a solution to this question, I occurred the same error. So I install the python2. node gyp finds the python2.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33905626) – GuedesBF Feb 27 '23 at 21:37
0

It was admin vs local user issue for me !

My local developer windows user account had restricted access. With temporary admin access provided by IT team, I was installing python to all users or setting the system path variables rather than setting the user path variable path which didn`t resolve the issue.

What worked for me !

After few days of trial I installed the Python2 windows installer for just the local user (Select the option as shown below)

enter image description here

and ensured that the add to path was selected, here I selected the second option Entire feature will be installed on local hard drive

enter image description here

and then doing npm install it ran without errors

techloris_109
  • 547
  • 5
  • 13