Error: Cannot find module 'ffi' compiling ElectronJS project - node.js

I'm new on NodeJS/ElectronJS.
I need to use User.dll functions.
My actual situation is:
Windows 10 on Parallels
Node -v = 10.15.3 (LTS)
NPM -v = 6.9.0
I installed:
npm install --global --production windows-build-tools
npm install win32-api
npm install ffi (gives me several "\ffi.cc(***): warning C4996: 'v8::Value::To Object': .... deprecated)
I added var FFI = require('node-ffi'); in my "main.js" and when I try to compile with npm start
I obtain this error:
Error: Cannot find module 'node-ffi' at Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
What's wrong?

The following steps fixed my issue (major pain in the ***)
Make sure the node gyp compiler is installed
npm install -g node-gyp
Install the FFI package into the local project
npm install --save ffi
I also needed to install ref-array (part of example code)
npm install ref-array --save
Go into the node_modules/ffi directory and do an NPM install to make sure it's got all it's dependencies
cd node_modules/ffi
npm install
Get back out of the node_modules/ffi folder
cd ../../
Install the electron rebuild tools
npm install --save-dev electron-rebuild
Run the electron rebuild script (I'm running on Windows, hence .cmd)
.\node_modules\.bin\electron-rebuild.cmd
So simple (NOT) :D

Solved with this:
How do I resolve "Cannot find module" error using Node.js?
using npm install
and then
Node - was compiled against a different Node.js version using NODE_MODULE_VERSION 51
using
./node_modules/.bin/electron-rebuild

Related

Cannot Install Npx

I am getting a strange error when trying to install npx. I have node, but it says I don't.
➜ Desktop brew install npm
Warning: node 14.4.0 is already installed and up-to-date
To reinstall 14.4.0, run `brew reinstall node`
➜ Desktop npm install -g npx
zsh: command not found: npm
Why is that happening?
npx is pre-bundled with npm .no need to install npx. if u want to start a new react project (I presume)give npx create-react-app project name given that you installed the latest node version.

Laravel Compilation "Error: Cannot Find PATH/node_modules/laravel-mix/.."

When I run commands like:
npm run dev
npm run watch
to compile my project. I receive an error that says the laravel-mix directory does not exist.
Error: Cannot find module 'PATH/node_modules/laravel-mix/setup/webpack.config.js'
I have deleted the node_modules directory and used npm install to attempt to get it to install properly and it still is not there. "Laravel-mix" is in the package.json file as a dependency, so to my knowledge running npm install or npm install laravel-mix should do the trick, but it isn't working. Any information about this would be greatly appreciated.
npm -v 6.14.1
node -v 12.16.2
Have you already run the following?
npm install laravel-mix
npm install cross-env

Should node-gyp be installed globally and locally?

I am looking at nodejs addon examples at https://github.com/nodejs/abi-stable-node-addon-examples.
The read-me section says that I must install node-gyp globally:
$ sudo npm install node-gyp -g
However, after installing node-gyp globally, does one also need to install it within the local project?
$ cd myproject
$ npm install node-gyp
It is good to install the node-gyp globally because main purpose of the node-gyp is to build the node native modules. node-gyp also need some tool like visual studio (in case of building on Windows)
and python which also installed globally.
after install globally no need to install it locally.

How to install certain node version from command line

I want to install node 6.9.4.
In windows console I try with this:
npm install node#v6.9.4
And it throws this error:
npm ERR! No compatible version found: node#v6.9.4
npm ERR! Valid install targets:
npm ERR! 0.0.0
In linux the result is similar. I try with
sudo npm install node#v6.9.4
and the output is:
npm ERR! version not found: node#6.9.4-cls
Is there a way to install certain node version with npm?
You should use nvm to install and manage node versions and not npm
NPM is the package manager for node and not a version manager.
To install a particular version of node using nvm, just do
nvm install v0.10.32
NPM should be used to install packages/modules.
So say you need to use request module for a particular project
You can do
npm install request
Both these support tons of options which could be found over the documentations
I recommend you use nvm: Nodev Version Manager
It would be as easy as
nvm install 6.9.4
It's a really good tool to manager all of your node versions.

How to install `yeoman` latest version?

I installed the node as new version. once i installed i checked in cmd for like this:
C:\Users\Mohamed.Arif>node --version && npm --version
v0.10.35
1.4.28
But after I installed the node, npm I am trying to install the latest yeoman. in their website, i noted the npm version requires v2.1.0+ - i confused here. how to i install the npm as they requested?
I am running the latest version of node only.
Install prerequisites
Before installing Yeoman, you will need the following:
Node.js v0.10.x+
npm (which comes bundled with Node) v2.1.0+
git
You can check if you have Node and npm installed by typing:
http://yeoman.io/codelab/setup.html
What is wrong here? I am working with windows7.
Thanks in advance!
See How do I update npm on Windows?
tl;dr - npm -g install npm does work, but the old version of npm is still in your PATH.
Option 3: navigate to C:\Program Files (x86)\nodejs with cmd.exe and then run
the installation without -g:
npm install npm

Resources