Unable to build native packages for node - node.js

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.

Fixed the issue for myself:
Delete node modules folder
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
Go to ~/.npmrc and make sure these are your settings:
msvs_version=2015
python=python2.7

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.

Related

Angular/Visual Studio: "ng is needed... npm is needed"

Using: Windows 10, Visual Studio 2022 17.1.0 (soon to be updated).
I come from the age when I would just copy the JavaScript files of a library in a subfolder of my website/application, add some <script...> tag to the adequate pages and call it installed...
But right now I'm trying to initiate my first Angular 2+ project. I'm trying to start from "Standalone TypeScript Angular Project" template.
But Visual Studio won't create my project, it writes in red
ng is needed (...)
npm is needed (...)
So I checked how to install ng... I needed npm, I checked how to install npm... I read it's recommended to install it through nvm... so I installed nmv, then npm, then ng ( v16.15.1 )... but Visual Studio still won't create my project and keeps requiring npm and ng.
What am I missing?
(I tried searching the Internet but mostly found a bunch of unrelated references and dead links.)
Here are the precise things I ran so far:
nvm-setup.exe
(I installed it in a custom folder of D:\ as I want this kind of tools to go there.)
nvm install lts
This installed npm in a subfolder of my customer folder.
npm install -g #angular/cli
This installed ng in a the same folder as npm + a subfolder.
I added '[...]/v16.15.1' (which contains npm.cmd, ng.cmd and node.exe) to the PATH "environment variable", but the problem remains unchanged.
Solved: after previous step, I needed to restart Visual Studio, but as I kept re-launching Visual Studio from Visual Studio Installer, it didn't work as a restart. Effectively closing the Installer and just relaunching Visual Studio refreshed things and it finally worked.
Solved: I needed to add the path that contains npm, ng and node to Windows "user and/or system Environment Variables".
And I also needed to restart Visual Studio (including closing Visual Studio Installer).

Installing --global windows-build-tools never completes

I am trying to install --global windows-build-tools by running below command
npm install --global windows-build-tools -verbose
No matter if I try through PowerShell or CMD (both as Administrator), the installation gets stuck in the same step.
npm info run windows-build-tools#5.2.2 postinstall node_modules/windows-build-tools node ./dist/index.js
[##################] | reify:resolve: info run windows-build-tools#5.2.2 postinstall node_modules/windows-build-tools node ./dist/index.js
Is there a reason why this might not complete?
According to the windows-build-tools repo
Please note that the official Node.js for Windows installer can now
automatically install the required tools. That's likely a much better
option than the module listed here (windows-build-tools).
recommended approach:
Go to node-download-page
Download LTS version for windows
Follow the installation instructions
When you got to this window, check the checkbox
After the installation it will prompt you to this window, it will automatically download the necessary dependencies
If you want to use this package(not recommended):
You should try to roll back to version 4.0.0
Run the command-line as administrator and try this:
npm install --global windows-build-tools#4.0.0
related question
If you're having trouble installing windows-build-tools (which I had a problem with recently), you should roll back to version 4.0.0.
Run PowerShell as Administrator, and then type in the following command (assuming you have node and npm installed).
npm install --global windows-build-tools#4.0.0
This process can take some time, so please be patient.
Built-in Node.js Build Tools
There are built-in Node.js build tools, so it is recommended to use this. In fact, if you go on the npm or GitHub page of the windows-build-tools package, it will say that you should use the Node.js build tools.
To do this, go to the official Node.js download website, and download the LTS version. Then, run the installer. At a point in the installation, it will have a checkbox that says Automatically install the recommended tools. Make sure to check that!
When you install it, it will also install Chocolatey, and install the build tools like the windows-build-tools package.
Even though both of these work, it is recommended to use the Node.js built tools!
Following this thread for a while now.
Disclaimer: Please note that I know this is not directly answering your question about why the process gets stuck but I want to share my solution anyway.
The installation via chocolatey did not work for me, as mentioned in:
https://github.com/felixrieseberg/windows-build-tools/issues/245
https://github.com/felixrieseberg/windows-build-tools/issues/152
Then, I found this microsoft page. On this page, the person asked this question:
I tried to install the Microsoft Visual C++ Build tools. The installer
(filename is visualcppbuildtools_full.exe) stops right after the start
of the installation it says a setup package is missing or damaged("Ein
Setuppaket fehlt oder ist beschÃĪdigt"). The option to download it
again doesnt work. Downloading the installer again doesnt help. Trying
to do an offline installation doesnt work either and I get the same
error. How can I find out what exactly the problem is and how can I
solve it?
The solution mentions the page https://my.visualstudio.com/Download that provides different build tool versions:
I was able to download and install "Build Tools for Visual Studio 2017 (version 15.9)".

Visual studio scaffold nodejs missing all modules?

I used visual studio to create an node express 4 project. However it cannot run and all the entries under npm show (missing). I cannot find the node_modules folder too.
It doesn't install them automatically. Either run npm install from a command window, or right click on the "npm" item in the project structure and do the install that way. I would recommend doing it through the command prompt though, if you are on a 64 bit machine.

Problems running the ripple emulator on Visual Studio 2013

I am trying to run the ripple emulator on Visual Studio, however I cannot seem to get pass the cannot find module './lib/plugin'error as follows:
C:\Users[user name]\Documents\Visual Studio 2013\Projects\Cordova\Cordova>call "C:\Program Files (x86)\nodejs\"\nodevars.bat
Your environment has been set up for using Node.js 0.10.33 (ia32) and npm.
------ Ensuring correct global installation of package from source package directory: E:\PROGRAM FILES (X86)\VISUAL STUDIO\COMMON7\IDE\EXTENSIONS\FUBXMEK2.O2B\packages\vs-mda
1>MDAVSCLI : error : Cannot find module './lib/plugin'
PS: The previous error I got was cannot find module 'q' however this was resolved by running npm install from CLI.
I am trying to create a Cordova application using Visual Studio. Any ideas how I can resolve the above error?
It seems something went wrong while installing vs-mda, you can try following to re-install:
Close Visual Studio
Open cmd
npm install -g [path to vs-mda example C:\Users[user-name]\AppData\Roaming\npm\node_modules\vs-mda]
npm install -g [path to vs-mda-targets example C:\Users[user-name]\AppData\Roaming\npm\node_modules\vs-mda-targets]
OR
Go to Tools --> Options --> Tools for Apache Cordova --> Cordova Tools --> Clear Cordova Cache
For the second method above (Clear Cordova Data) try running visual studio as administrator if it fails the first time around.

Not being able to run bower in VS 2012

Since yesterday I have been trying to install and use bower for managing my dependencies. After going through many articles although I have been able to install it. I am not being able to run it. Beside many articles I also followed this video:
Bower running in Package Manager Console in Visual Studio install
As the video is in some other languages even though I followed all the commonds, I could not get
$env:path
After doing everything when I type bower in the Package manager console, it gives me error
Thanks in advance for helping me out.
PS: I have already installed npm and node.
In order to use Bower correctly in Windows, you need to install msysgit correctly. This is the requirement as specified in bower github https://github.com/bower/bower#a-note-for-windows-users.
The option you have to select during installation is Run Git from the Windows Command Prompt.
After successful installation. Restart Visual Studio and then you are good to go.
In my case, after installing msysgit, I installed bower using:
PM> Install-Package Bower
Above step automatically installed dependencies (node.js, jquery)
I also had to specify relative path to bower.cmd:
PM>.\MyProject.bin\bower.cmd install semantic-ui

Resources