Unable to build native packages for node

3k views Asked by At

So Im running an Electron app that has some native modules of one them being a package called better-sqlite3. I run yarn and yarn is able to install all packages without a problem but when it gets to the building steps, everything breaks.

I get a bunch of diffrent node-gyp error outputs of which 2 I have been able to save so I can show here here is the important part of the error output for the first error:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.targets(67,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\bepop\Documents\DeveloperData\Clippy\app\node_modules\better-sqlite3\build\deps\action_before_build.vcxproj]

Full error

In terms of this error I've tried doing multiple things such as installing microsoft visual build tools in many diffrent ways such as manually going to their website and downloading the IDE, I've also tried installing the build tools through NPM with:

npm install --global --production windows-build-tools

It always succesfully installs the build tools but still it errors out on me, I've also tried editing the npm config with:npm config set msvs_version 2017 still doesnt work. I have also tried going to the installation of the Visual Studio and manually checking: "VC++ 2017 version 15.7 v14.14 latest v141 tools" Also nothing.

I do remember at some point I was able to get everything to build normally with Windows 10 and I never had a problem but not anymore. I've been trying to fix this issue by myself for months now and I've just been sticking on working on the project on my macbook where it never has issues building the better-sqlite3 package.

1 more thing I have tried is completely wiping my computer from everything and starting fresh because at some point i had changed so many things that I lost track of what I had installed and what I did not.

If I remove the better-sqlite3 package from the package.json file everything runs smoothly and I am able to run my project normally but I need the better-sqlite3 package. I could use another package but I really shouldnt have to do that, I'd like to get to the bottom of why this i snot building.

Edit:

Updated: I added Microsoft build tools v14.0.23107.0 to my pats variable and now it outputs error:

C:\Users\bepop\Documents\DeveloperData\Clippy\node_modules\integer\build\integer.vcxproj(21,3): 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.

2

There are 2 answers

2
Kevin Hernandez On BEST ANSWER

Fixed the issue for myself:

  1. Delete node modules folder

  1. Open PowerShell with admin privileges and run in order

    npm install --global --production --vs2015 --add-python-to-path windows-build-tools

    npm install --global --production --add-python-to-path windows-build-tools node-gyp

  1. Go to ~/.npmrc and make sure these are your settings:

    msvs_version=2015

    python=python2.7

1
Sunny Goel On

First remove all the visual studio version installed from your system , and also remove the entries from path and system variable .

and follow the below URL https://github.com/nodejs/node-gyp#readme

Every thing run fine after removing of better-sqlite3 this package entry from package.json because other packages don't have any native dependency . and this better-sqlite3 is native module after downloading, this module get build using tool node-gpy that will need two things installed on your system i.e. python and visual studio .

So try to follow the above URL steps.

it will definitely work.