Last active
April 7, 2022 12:16
-
-
Save vivekDebugs/a8a1b6f8c5929483a29d12639a7f51b7 to your computer and use it in GitHub Desktop.
Work-around for node-gyp issues on Windows 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----------------INSTALLING PYTHON------------------------------------------------------------ | |
1. Install Python (version should be >=3.6.0, preferably v3.8.5) | |
2. Install Python v2.7 | |
3. Add both the version to path (v2.7 should come before v3.8.5) | |
4. Add PYTHON environment variable with value pointing to Python3.8.5 executable file | |
______________________________________________________________________________________________ | |
----------------INSTALLING VSBUILD TOOLS------------------------------------------------------ | |
Stick to one version. Let's go with Visual Studio 2019 | |
1. Install Visual Studio Build Tools (using "Visual C++ build tools" workload OR using the "Desktop development with C++" workload) | |
Link -> https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools | |
NOTE -> DO NOT uncheck any optional packages (to make sure all the tools are downloaded) | |
REFER -> https://devblogs.microsoft.com/cppblog/introducing-the-visual-studio-build-tools/#recap-of-the-visual-c-and-build-tools | |
--------OTHER WAYS OF INSTALLING VSBULD TOOLS---------- | |
1. On an elevated terminal (Admin Rights) :- | |
Navigate to the installtion folder and run | |
vs_buildtools.exe –quiet –add Microsoft.VisualStudio.Workload.VCTools –includeOptional | |
REFER -> https://devblogs.microsoft.com/cppblog/introducing-the-visual-studio-build-tools/#command-line-silent-installs | |
2. On an elevated terminal (Admin Rights) :- | |
npm install -g windows-build-tools | |
(this step is not recommended, since it has active issues) | |
3. While installing Node, select 'Automatically install necessary tools', this will install all the Tools required to compile Native Modules. | |
NOTE -> You don't need to install Python explicitly if you follow this step | |
Image -> https://user-images.githubusercontent.com/13296622/125211835-8cb2c600-e266-11eb-8316-92732e0b7f8c.png | |
RESTARTING PC IS RECOMMENDED AFTER EACH SUCCESSFULL INSTALLATION | |
______________________________________________________________________________________________ | |
---------------INSTALLING NODE-GYP AND NODE-SASS---------------------------------------------- | |
On an elevated terminal (Admin Rights) | |
1. npm i -g node-gyp | |
2. npm i -g node-sass | |
______________________________________________________________________________________________ | |
----------------NPM CONFIGS------------------------------------------------------------------- | |
On an elevated terminal (Admin Rights) | |
1. npm config set python path\to\python3\exeFile | |
2. npm config set msbuild_path path\to\msbuild\exeFile | |
msbuild.exe path -> C:\Program Files (x86)\Microsoft Visual Studio\<YEAR>\BuildTools\MSBuild\Current\Bin\MSBuild.exe | |
YEAR is 2019 in case of VSBUILDTOOLS 2019 | |
YEAR is 2017 in case of VSBUILDTOOLS 2017 | |
3. npm config set msvs_version 2019 | |
NOTE -> These steps may not be required if Build tools were installed via 'OTHER WAYS OF INSTALLING VSBUILD TOOLS' | |
______________________________________________________________________________________________ | |
--------------------ERRORS YOU MIGHT RUN INTO------------------------------------------------- | |
1. error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. | |
Confirm that the path in the <Import> declaration is correct, and that the file exists | |
on disk. | |
This error should not encounter unless the VSBUILDTools installation was not messed up with. | |
Work-arond :- | |
FOR 2019, | |
By default VCTargetsPath points to 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160' | |
If not, add VCTargetsPath environment variable with this path | |
FOR 2017, | |
By default VCTargetsPath points to 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\' | |
If not, add VCTargesPath environment variable with this path | |
REFER -> https://docs.microsoft.com/en-us/cpp/build/reference/msbuild-visual-cpp-overview | |
-> https://stackoverflow.com/questions/16092169/why-does-msbuild-look-in-c-for-microsoft-cpp-default-props-instead-of-c-progr | |
If there are UNSUPPORTED ENGINE issues, there is no way around other than installing demanding versions. | |
In my case, it asked for node v12.14.1 or v14.0.0 and npm v6.11.0 or v7.5.6 | |
______________________________________________________________________________________________ | |
**npm install should now work fine** | |
----------------OTHER REFERENCES-------------------------------------------------------------- | |
1. https://stackoverflow.com/questions/57750317/npm-install-not-installing-because-of-node-gyp | |
2. https://stackoverflow.com/questions/52089305/gyp-err-stack-error-c-program-files-x86-msbuild-14-0-bin-msbuild-exe | |
3. https://github.com/nodejs/node-gyp#on-windows | |
4. https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules | |
______________________________________________________________________________________________ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment