Electron ffi rebuild issue: command not found - node.js

I am struggling with the error:
Uncaught Exception:
Error: A dynamic link library (DLL) initialization routine failed."
After some research and debugging, the likely issue is that the node module ffi has not been "rebuilt" for the electron environment. I have tried following the steps at https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md to rebuild the package, but method 1, when copied to the letter, didn't work.
Method 2 of "Installing module and rebuilding for Electron" doesn't work because entering ./node_modules/.bin/electron-rebuild.cmd (I'm on Windows) doesn't work- Bash simply says "command not found" and I don't see others with this issue. I've tried even running it from PowerShell in case git bash was causing issues, but I get a similar issue, although I also get an error stating:
At line:1 char:1
+electron-rebuild.cmd
+~~~~~~~~~~~~~~~~~~~
_CategoryInfo : ObjectNotFound: (electron-rebuild.cmd:String) [], CommandNotFoundException
+FullyQualifiedErrorID : CommandNotFoundException
I don't understand method 3 (manually building for Electron) and am hesitant to use it- namely I'm unsure of why there isn't an argument in the manual build command for specifying what package needs to be rebuilt.
I have retried installing Electron Rebuild to the letter per the instructions in https://github.com/electron/electron-rebuild multiple times (npm install --save-dev electron-rebuild) in project folder. It seems to be installed in the correct location.
Why is electron-rebuild not being recognized? What will it take to get ffi installed properly?
I'd also appreciate if someone could point me to some additional places to educate myself on what I might be missing with my conceptualization of this issue. Thanks in advance!

Ok, this works for me:
Ensure Python 2.7.X is installed.
Get and Install Visual Studio Build Tools (eg. http://landinghub.visualstudio.com/visual-cpp-build-tools )
To use the correct msvs version during rebuild enter this in eg. a powershell: npm config set msvs_version 2015 --global
In my minimal example I used the following package.json:
{
"name": "stack_ffi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"rebuild": "electron-rebuild -f -w ffi"
},
"author": "",
"license": "XXX",
"devDependencies": {
"electron": "2.0.2",
"electron-rebuild": "1.7.3"
},
"dependencies": {
"ffi": "2.2.0",
"ref": "1.3.5"
}
}
Run npm run install and then npm run rebuild
Notes:
On my first try electron did not install correctly so I have deleted
the ./node_modules/electron folder and ran npm run install again.
When I tried to use a sqlite3.dll on Windows the online example (https://github.com/node-ffi/node-ffi/blob/master/example/sqlite.js) did
not work. I had to remove the leading "lib" part from the library string: var SQLite3 = ffi.Library('sqlite3', {...}); //was 'libsqlite3'.
I tested it on node 7.4.0 and 8.0.0. If it fails on your node version
I have the theory that v8::Object::ForceSet was dropped on later
versions.
I had to ensure that Windows can find my dll's. For example I
included the sqlite3 x64 dlls by adding their folder
location to the PATH env variable.

Look out your python version, ffi only support python 2x because of node-gyp only support python 2x.
Try to uninstall python 3x and reinstall python 2x.

Related

npm install fail for multiple versions of node

I'm not very used to working with node and I'm having a nightmare installing the packages for a project.
I'm using vagrant/VirtualBox Homestead on Windows 10 for a Laravel (5.2) project. When doing npm install I've had a whole bunch errors - I can't remember them all specifically, but I'm wondering if there is some big picture issue I'm missing.
My first attempt was with a recent node node version - 12.something I think.
Then I was told that "some of those older projects used v8, I think", so I used nvm to do that and got a whole bunch of different issues. Some involved sym links, so I deleted node_modules and tried with --no-bin-links. That didn't work, and one of the errors, when I looked on SO, was down to node version, so I tried v9.0.0, which gave different problems.
How hard can it be?
I don't know enough about this frontend stuff to know if it's normal to have so much trouble, or if I have not been given sufficient information - e.g. "you absolutely need to use node version 8.1.3, with these specific other details..." or something like that.
Does anyone have any suggestions on how to get this working? The node-sass package seems to be a significant culprit in the overall failage of the installation...
Below is my package.json
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^5.0.0",
"bootstrap-sass": "^3.0.0"
},
"dependencies": {
"node-sass": "^4.1.0"
}
}
I was heading same problem last time. Here is what I did:
Using terminal in homestead directory run command vagrant plugin install vagrant-winnfsd it will install plugin that allows you to use NFS protocol on Windows.
Edit you Homestead.yaml file like that:
folders:
    - map: ~/Projects
    to: /home/vagrant/code
    type: "nfs"
Run command vagrant reload --provision. After that when you use secure shell - vagrant ssh you should be able to run npm install from inside you project directory.

"npm run" commands fail on Windows

I am using Windows PowerShell ISE with administrator privileges. My project uses webpack, which is installed as a local dependency with npm. I have a "script" defined in package.json:
"build": "webpack --progress --config resources/assets/build/webpack.config.js",
When I execute npm run build I get the error message 'webpack' is not recognized as an internal or external command, but if I copy the webpack command and execute that it works fine. I'm not going to list my whole system PATH here, but it includes .\node_modules\.bin at the beginning. Clearly Windows has no problem finding webpack but Node for some reason can't.
I tried running npm run build in a privilege-less Command Line, no difference. I upgraded to the latest versions of Node and npm (13.0.1 and 6.12.1, respectively), to no avail. I even tried prefixing the command in package.json with ./node_modules/.bin/ but that didn't work.
Please don't suggest that I install webpack globally as that is not a real solution. Node is giving me this error with all locally-installed commands, not just webpack. I should be able to run commands locally through npm.
if you're using a recent version of npm, you can try
npx webpack ....
alternatively, you can install webpack locally and specify the exact path
node_modules/webpack/bin/webpack.js ....
In the end, I had to bite the bullet and install webpack globally.

Zipping up Node App and having dependencies work out of box

I created a Node app that relies on a dependency (Jest) that is just for running tests.
I want to zip this app up and run it and its tests on another machine that has node installed.
My package.json includes
"scripts": {
"test": "jest"
},
and jest is included in the app's npm_modules folder.
The tests work perfectly on the machine that the app was developed on. However, upon extracting the zip and running on another computer, I get an error that jest is not found.
I then reinstalled jest without '--save-dev' and installed it for production use, thinking this would resolve the error, but it did not.
I thought the point of having npm_modules and using 'npm install' was so that the app's dependencies can all be localized and portable i.e. not having host machine have to install modules separately.
Is there any way to resolve this? Thanks!
According to "scripts": { "test": "jest" }, you have jest installed globally on source machine. Change it to "scripts": { "test": "node_modules/.bin/jest" },
Try using pkg
Github Page
npm
If you just need to run it on the second machine, pkg should let you package it as a standalone executable.
I'm guessing the problem is either that Jest installs differently based on the OS. It may also be a problem with import-local, one of the packages that Jest depends on.

Set up Socket.IO to run on Node Windows

I am new to programming and I am doing the WebRTC codelab here: https://codelabs.developers.google.com/codelabs/webrtc-web/#6
I am at the part titled "Set up Socket.IO to run on Node" where it says "To install dependencies, run the following from the command line terminal in your work directory:
npm install", however, when I type npm install the command prompt in Windows, it does not recognize the command. I feel like this should be pretty easy, so am I missing something?
Set up Socket.IO to run on Node
For this and the following steps, you'll run Socket.IO on Node.
At the top level of your work directory create a file named package.json with the following contents:
{
"name": "webrtc-codelab",
"version": "0.0.1",
"description": "WebRTC codelab",
"dependencies": {
"node-static": "0.7.7",
"socket.io": "1.2.0"
}
}
This is an app manifest that tells Node Package Manager (npm) what project dependencies to install.
To install dependencies, run the following from the command line terminal in your work directory:
npm install
You should see an installation log that ends something like this:
enter image description here

How to make npm scripts refer to local packages?

I am working on a project and I want to use JSdoc for documentation. I have listed it in devDependencies and created a script to run it. My package.jsonlooks like:
"scripts": {
"doc": "jsdoc -c ./conf.json"
},
"devDependencies": {
"jsdoc": "^3.4.3"
}
Cloning my project on another machine and typing npm install installs jsdoc to the node_modules folder.
However, when I run npm run doc, I get a large error, the center of which is: 'jsdoc' is not recognized as an internal or external command
This is because JSdoc is installed in node_modules not my local path.
What is the best way to point npm-run commands to my locally installed modules? Also, what is the point of having dependencies such as JSdoc listed in devDependencies (thus installed in node_modules) when they can not be used from there?

Resources