I'm working on native Node.js addon and following nan docs
I included nan into binding.gyp like:
"include_dirs" : [ "<!(node -e \"require('nan')\")" ]
Also nan is in npm dependencies.
But when I install the package inside the another node module node-gyp is failed with error
> nnb@1.0.2 install /Users/Shopgate/sandbox/stress/node_modules/nnb
> node-gyp rebuild
module.js:338
throw err;
^
Error: Cannot find module 'nan'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at [eval]:1:1
at Object.exports.runInThisContext (vm.js:74:17)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:460:26)
at evalScript (node.js:431:25)
at startup (node.js:90:7)
gyp: Call to 'node -e "require('nan')"' returned exit status 1. while trying to load binding.gyp
Install
nan
globally:npm i -g nan
And then,
export NODE_PATH=$(npm root -g)
In my case, it was because of some dependencies missing in the
package-lock
file. I solved it by removing it and running$ npm install
again.I am little bit late for a party. But what worked for me was to re-install all
node_modules
usingrm -rf node_modules && npm install
Unfortunately I had this issue, anything that had 'npm' in it was immediately returned with thrown error.
I had to remove my node & npm files
uninstall and reinstall instruction I followed were here (stackoverflow):
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
I then followed the rabbit trail all the way through every issue!
Don't immediately jump to SO (stackoverflow) at the first sign of friction, the command window (cli) will "oddly enough" give you the right answers to everything (I did however hit about 2 hurdles I referred to SO for, mainly to be on the safe side).
-- I ran into some friction with a python framework file being in a place that made homebrew throw a warning resolve with.
-- and a kegs link warning resolved with my own write up here.
brew install node
-- I had another
brew link issue
, easy enough, as my write-up above for kegs link warning would just need to be walked through again, so I thought. I then was getting an error saying I can notbrew link --overwrite node
that file (privileges or something if I recall, none-the-less resolved here).Finally
It was at this point everything was working well. -- Remember! there were simple steps inbetween that I literally just obeyed the command prompts in the cli, such as:
brew wanting me to delete files via a given path:
-- open finder> [at top of MacBook "monitor tool bar"] Go>go to folder...>copy&paste the path supplied by brew in cli window>it will find that director/file then delete appropriate directory/file
-- continue these steps until
brew update
is completely satisfied.As I said this final part was just simple following of direction from brew responses directly.
I hope this walkthrough helps someone bypass the issues I had a bit faster, and thank you to the community that spent their time helping me with solutions that I have linked to in this answer.
don't cry over spilt code, keep supporting the community.
Not ideal but it works if you install nan first.