85

We are having problems running "npm install" on our project. A certain file cannot be found :

fatal error C1083: Cannot open include file: 'windows.h'

It appears to be coming from the node-gyp module :

c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_lo ad_hook.c(13):

fatal error C1083: Cannot open include file: 'windows.h': No suc h file or directory [D:\ngs-frontend-next\node_modules\browser-sync\node_module s\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil\buil d\binding.sln]

This node-gyp seems to be a never ending source of pain for us. At first it complained that it needed python, so we installed that. Then it complained that it needed VCBuild, which we installed (using .NET 2.0 SDK), now we have this error. It's almost as if the errors are getting more and more obscure, and it feels like we are going down some wrong path.

The strange thing is, that other people in our team have zero problems running the npm-install.

The full error looks like this :

c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_lo ad_hook.c(13):

fatal error C1083: Cannot open include file: 'windows.h': No suc h file or directory [D:\ngs-frontend-next\node_modules\browser-sync\node_module s\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil\buil d\binding.sln]

gyp ERR! build error gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1 stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node _modules\node-gyp\lib\build.js:270:23) gyp ERR! stack at emitTwo (events.js:87:13) gyp ERR! stack at ChildProcess.emit (events.js:172:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_proces s.js:200:12) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodej s\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd D:\ngs-frontend-next\node_modules\browser-sync\node_modules\socket. io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil gyp ERR! node -v v4.2.2 gyp ERR! node-gyp -v v3.0.3 gyp ERR! not ok npm WARN optional dep failed, continuing utf-8-validate@1.2.1

gifsicle@3.0.3 postinstall D:\ngs-frontend-next\node_modules\gulp-imagemin\nod e_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle node lib/install.js

Out package.json looks like this :

{
  "name": "Fast-nunjucks",
  "version": "0.0.1",
  "description": "A simple boilerplate using nunjucks as a template engine",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/willianjusten/Fast-nunjucks.git"
  },
  "keywords": [
    "nunjucks",
    "node",
    "gulp",
    "stylus"
  ],
  "author": "Willian Justen de Vasconcellos",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/willianjusten/Fast-nunjucks/issues"
  },
  "homepage": "https://github.com/willianjusten/Fast-nunjucks",
  "devDependencies": {
    "autoprefixer-stylus": "^0.7.1",
    "browser-sync": "^2.8.2",
    "gulp": "^3.9.0",
    "gulp-cache": "^0.3.0",
    "gulp-concat": "^2.6.0",
    "gulp-if": "^1.2.5",
    "gulp-imagemin": "^2.3.0",
    "gulp-minify-html": "^1.0.4",
    "gulp-nunjucks-html": "^1.2.2",
    "gulp-order": "^1.1.1",
    "gulp-plumber": "^1.0.1",
    "gulp-stylus": "^2.0.6",
    "gulp-uglify": "^1.2.0",
    "gulp-util": "^3.0.6",
    "jeet": "^6.1.2",
    "kouto-swiss": "^0.11.13",
    "minimist": "^1.1.3",
    "rupture": "^0.6.1"
  },
  "dependencies": {
    "gulp-install": "^0.6.0"
  }
}
Andrew
  • 6,808
  • 3
  • 18
  • 33
Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
  • 2
    "The strange thing is, that other people in our team have zero problems running the npm-install." - make sure everyone's on the same version of node. – xdumaine Nov 24 '15 at 14:48
  • Did you solve this problem? I have something like this one. Can you check this issue: http://stackoverflow.com/questions/34335043/troubles-with-npm-and-node-gyp-in-windows May be you have some useful advices for me. – Dmytro Medvid Dec 26 '15 at 09:30
  • 1
    I tried several days for this build issue, on my PC with Visual Studio 2010 / 2013 / 2015 installed, with no success. And then finally end up built it inside a pure Windows VM successfully. I don't like it, but it worked. – Val Dec 27 '16 at 10:26
  • 1
    Oh man. I don't update my apps often, but every single time I do, node-sass fails on npm install. It's getting really old. Is there not an alternative? – Ken Hadden Jul 15 '21 at 00:17
  • As an aside, when a build fails in this manner (with a node-gyp driven native compilation issue), is there a way to retain the partially compiled results/artifacts to investigate further? In my case I get the error, but then the compiled sources/binaries get cleaned up by the remainder of the npm process (so I have no way to troubleshoot the failure in more detail) – Janaka Bandara Jan 19 '22 at 14:26

18 Answers18

43

The error messages have caused confusion for me and have not helped me in resolving the errors completely.

The README.md for node-gyp project does a better job of listing down the installation instructions for Unix, Max OS X and Windows.

In Windows systems you can either go with Option 1 or Option 2 but the main thing is that you need to install the Visual C++ Build Tools.

The following quote is from the Windows installation section:

  • On Windows:
    • Visual C++ Build Environment:
      • Option 1: Install Visual C++ Build Tools using the Default Install option.
      • Option 2: Install Visual Studio 2015 (or modify an existing installation) and select Common Tools for Visual C++ during setup. This also works with the free Community and Express for Desktop editions.

      [Windows Vista / 7 only] requires .NET Framework 4.5.1
    • Install Python 2.7 (v3.x.x is not supported), and run
      npm config set python python2.7
      (or see below for further instructions on specifying the proper Python version and path.)
    • Launch cmd,
      npm config set msvs_version 2015

If the above steps didn't work for you, please visit Microsoft's Node.js Guidelines for Windows for additional tips.

Common instructions for Python configuration:

If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable:

$ node-gyp --python /path/to/python2.7

If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:

$ npm config set python /path/to/executable/python2.7

Successfully configured my system following the above instructions.

System Info

λ ver

Microsoft Windows [Version 6.1.7601]

λ node -v
v6.2.0
λ npm -v
3.9.2

Links to relevant tools / articles:

Visual C++ Build Tools

Visual Studio 2015

.NET Framework 4.5.1

Python 2.7

Microsoft's Node.js Guidelines for Windows

Sourav Paul
  • 616
  • 5
  • 5
38

I tried all the solutions above but none of them worked. My problem was with some files in the root directory that I had to delete:

package-lock.json and yarn.lock and yarn-error.log

after removing these files, I ran:

npm cache clean --force

then I ran the command:

npm install

and the error was gone

Mahdieh Shavandi
  • 4,906
  • 32
  • 41
23

Try to install again with --force option:

npm install --force

If this doesn't work try to update npm globally:

npm update -g npm 

and try again with the --force option.

David Vega
  • 579
  • 3
  • 13
  • 1
    didn't work. But i think it has something to do with node-gyp requirements. On the website it says it needs Visual Studio installed. – Oliver Watkins Nov 25 '15 at 10:34
  • I tried this approach... But it's didn't works for me. It's fires the same errors, as it was previously. Please check this issue: http://stackoverflow.com/questions/34335043/troubles-with-npm-and-node-gyp-in-windows Maybe you have some useful advices for me... – Dmytro Medvid Dec 26 '15 at 09:26
19

I had nearly the same problem on Mac. I got lot's of spam error messages, but finally I recognized the issue, it was a version missmatch...

Description:

npm install failed on installing gyp (node-gyp):

npm ERR! gyp ERR! node -v v16.2.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok 
npm ERR! Build failed with error code: 1

Solution:

downgrade npm / node to stable version!

Try:

Install 'n': npm i -g n

Downgrade npm: sudo n stable

Rerun npm install and this works!

droebi
  • 872
  • 1
  • 14
  • 27
  • 2
    This answer should be promoted more! Tried to install node-sass, windows build tools, VC++ build tools, none of them works. Downgrading my node (using nvm) is the best method I've ever done. – Radityo Ardi Jul 01 '22 at 15:15
  • 1
    What if i don't want to downgrade node version? – Bilal Hussain Aug 26 '22 at 06:42
  • The problem here is that the versions of node and node-gyp do not match, if you "downgrade" to stable version, the necessary version of gyp will be also installed correctly. By the way you can also use `nvm` to install different versions of node by using `nvm use` command, see https://github.com/nvm-sh/nvm – droebi Aug 26 '22 at 06:59
5

The last time I saw a similar error it was because I was using the wrong version of npm and/or node for one of my dependencies. Try upgrading these and try again.

Before trying again remove your node_modules directory.

You may need to investigate what versions of npm and node your dependencies need. You could try the latest versions of all your dependencies, node and npm.

Check what versions your colleagues are using.

What OS are you using? That can have an impact as version of CLANG maybe different.

Softinio
  • 638
  • 1
  • 6
  • 19
  • remove node_modules from the nodejs directory as well? – Oliver Watkins Nov 24 '15 at 16:59
  • Only if you are going to re-install the global packages also – Softinio Nov 24 '15 at 18:19
  • using windows 7. Tried everything you said but still have the same problem. Seems like i need Visual Studio or something like that installed. – Oliver Watkins Nov 25 '15 at 10:35
  • Can you add more details how to check all dependenies? I have a similar problem and I added some details here: http://stackoverflow.com/questions/34335043/troubles-with-npm-and-node-gyp-in-windows/34344232 May be you have some useful advices for me? – Dmytro Medvid Dec 26 '15 at 09:22
4

for this solved it ( OS X ):

rm -rf  ~/.node_gyp and
sudo npm install -g node-gyp@3.4.0
cd /usr/local/lib
sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib 
brew install gcc
npm install
A. Khaled
  • 1,468
  • 16
  • 28
Orr
  • 4,740
  • 3
  • 28
  • 31
4

If you are using "node-sass", upgrade it to version 5.0.0, make sure that you have build tools 2017 and Python 3 installed, and issue these commands prior to npm install

npm config set msvs_version 2017

npm config set python npm config set python C:\Users\username\AppData\Local\Programs\Python\Python39\python.exe

Ababneh A
  • 1,104
  • 4
  • 15
  • 32
3

Try delete current node_modules folder and run Command as regular user, non administrator or root

Aloiso Gomes
  • 640
  • 6
  • 12
2
  1. Install VC++ Build Tools Technical Preview [Windows 7 only] requires .NET Framework 4.5.1

  2. Install Python 2.7, and add it to your PATH, npm config set python python2.7

  3. Launch cmd, npm config set msvs_version 2015 --global (this is instead of npm install [package name] --msvs_version=2015 every time.)

4.SO MUCH npm install :tada:

sabari
  • 2,595
  • 5
  • 28
  • 44
  • Hi! I have the same trouble with node-gyp under the Windows. I do exactly what you described, but it not works for me. It's very important to me to solve this issue. Can you help with it? I added latest update in my error log file and here is it: https://github.com/web-jenezis/jenezis-project-bootstrap/blob/master/errors.log Also I described my problem with more details in this issue: http://stackoverflow.com/questions/34335043/troubles-with-npm-and-node-gyp-in-windows/34344232 Please, help me if you can – Dmytro Medvid Dec 26 '15 at 09:20
2

Post my solution here in case anyone like me using Windows 10 still has the error after installing many Microsoft associated build tools.

All you need are:

Windows 10 64 bit

python 2.7.x

Visual Studio 2013

I've tried Visual Studio 2015 before but it didn't work at all.


  1. First of all, I uninstall all the Microsoft associated build tools. (If you didn't install anything to try to solve this problem before, skip this step.)

  2. Install Visual Studio 2013.

  3. Config npm as @Sourav said:

Config python:

npm config set python /path/to/python2.7

Config msvs_version:

npm config set msvs_version 2013

Run a npm install or the npm command which occurs this error. It works for me!

BTW, this solution is from here.

Community
  • 1
  • 1
JavaNoScript
  • 2,345
  • 21
  • 27
2

Hey please try to install the windows build tools (global npm package)

This will fix your problem :-) You should be able to use your npm install command afterwards.

EvilBurrito
  • 823
  • 8
  • 14
2

Based on the node-gyp README, update npm npm i npm -g, and will bring in a newer version of node-gyp.

Hint: if you are on windows perform npm install --global --production windows-build-tools from an elevated PowerShell or CMD.exe (run as Administrator).

Javier Aviles
  • 7,952
  • 2
  • 22
  • 28
2

I was working on an older project and was encountering this error (or a very similar one with node-gyp) due to the package-lock being for an older version of node. After downgrading to that version, I was able to run npm install without issue.

isick
  • 1,467
  • 1
  • 12
  • 23
  • 1
    Was facing an error while building a docker image with node:latest which was causing an error of above mentioned. For solution i've checked local node version and applied same from docker hub and goooossss. Issue gone. Thanks @isick – Harsh Patel Dec 31 '21 at 09:46
2

Delete package-lock.json Then restart your machine(if there were changes made to take effect) then run

npm install --legacy-peer-deps
1

For Windows 8 or 10:

Assuming node and npm installed already.

My node and npm version (At the time of writing this answer) :

node : 8.9.4

npm : 5.6.0

  1. First install python 2.x

  2. Make sure it is available on path

  3. Install Visual Studio Installer

  4. After installation, run it

  5. A new interface will open it where you can select various options.
  6. Now select Build Tools for Visual Studio 2017 from the available options and install it. You don't need to install Visual Studio.

enter image description here After the installation it should work perfectly.

WitVault
  • 23,445
  • 19
  • 103
  • 133
0

I am using yarn so I just ran yarn global add node-gyp to globally install node-gyp without using npm and it worked. I'm no more facing the error

For those using npm can do it using npm install -g node-gyp.

Make sure you know that running these commands will globally install node-gyp in your environment, probably outside the scope of your current app too. And in case you are running any other apps in the similar environment that are dependent on any particular version of node-gyp, you might face some troubles.

Adil
  • 21,278
  • 7
  • 27
  • 54
0

Install node version 14.20.0 ,while installing there will be an option to install necessary tools like chocolatey, python etc. , Click on that option and This should resolve the issue

0

Removing node-sass and installing sass solved this for me

npm uninstall node-sass

npm i sass --save