Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find module 'nan'

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

> [email protected] 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
like image 596
Rax Wunter Avatar asked Dec 25 '15 16:12

Rax Wunter


3 Answers

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.

like image 60
Leonardo Emilio Dominguez Avatar answered Oct 14 '22 13:10

Leonardo Emilio Dominguez


Install nan globally:

npm i -g nan

And then,

export NODE_PATH=$(npm root -g)

like image 32
Emre Tapcı Avatar answered Oct 14 '22 14:10

Emre Tapcı


Not ideal but it works if you install nan first.

$ npm install nan
like image 19
David Momenso Avatar answered Oct 14 '22 14:10

David Momenso