Error: Cannot find module 'nan' - node.js

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

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.

Install nan globally:
npm i -g nan
And then,
export NODE_PATH=$(npm root -g)

Not ideal but it works if you install nan first.
$ npm install nan

I had this exact error with node.js version v12.18.3 and npm 6.14.6.
Upgrading to node.js version v14.15.4 (which includes npm 6.14.10) resolved the issue. npm install ran successfully after the upgrade.
There was no need to install nan in any way.

Unfortunately I had this issue, anything that had 'npm' in it was immediately returned with thrown error.
module.js:471
throw err;
^
Error: Cannot find module 'number-is-nan'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/string-width/node_modules/code-point-at/index.js:2:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
cd: no such file or directory: /npm
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).
When going through the install of node, npm, & grunt via Install Node.js and npm with Homebrew.
-- 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.
Then when I needed to run: 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 not brew 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.

I am little bit late for a party. But what worked for me was to re-install all node_modules using rm -rf node_modules && npm install

Related

Error running npm command on Windows: graceful-fs

I have a ReactJS project and I was trying to use some of the PrimeReact components. At some point, I faced an error (can't remember exactly which one) and I tried to run an older version of NPM in a copy of my main directory.
Now, I get this error every time, even when I run npm command.
I've already tried to delete my node_modules folder, delete my project and clone it back from GitHub and also to reinstall NodeJS several times. I don't know what to do!
I have Windows 10 and I'm using NodeJS v12.16.0.
Thanks to anyone that offers some help
Update: I have never installed gulp. I suppose that maybe some dependency is using it but, because I can't run any npm command, I can't remove them D:
The error:
C:\Users\Carlos>npm
evalmachine.<anonymous>:35
} = primordials;
^
ReferenceError: primordials is not defined
at evalmachine.<anonymous>:35:5
at Object.<anonymous> (C:\Users\Carlos\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\fs.js:12:1)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load (internal/modules/cjs/loader.js:900:14)
at Module.require (internal/modules/cjs/loader.js:1043:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\Carlos\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\graceful-fs.js:3:27)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
It might be an error related with gulp and node v12 conflict. If you have the gulp installed globally in your environment and you can uninstall without problems, you can try it. To help with commands, check if you have the gulp installed, typing this in your command line interface:
gulp -v
Uninstall your version:
npm uninstall -g gulp

Cannot find module 'readable-stream' when using npm

I installed nodejs and am trying to use npm on my Windows machine. I downloaded all the files from nodejs website. I tried to install the latest 4.4.2 version or 5.10.1 version, but I always got error Cannot find module 'readable-stream' when I tried to run commands using npm.
C:\Users\Ealon>node -v
v5.10.1
C:\Users\Ealon>npm -v
module.js:341
throw err;
^
Error: Cannot find module 'readable-stream'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (C:\Users\Ealon\AppData\Roaming\npm\node_modules\npm\node
modules\npmlog\node_modules\are-we-there-yet\index.js:2:14)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
I tried to reinstall it again and again, still could not fix this problem. And the answers in another similar question do not help because I always got error when I tried to run any command using npm. Any help is appreciated. Thanks!
Judging from the line C:\Users\Ealon\AppData\Roaming\npm\node_modules\npm\node
modules\npmlog\node_modules\are-we-there-yet\index.js:2:14 in the stack trace, I believe that you had a global installation of npm which internally had a dependency on are-we-there-yet, which I confirmed has a dependency on readable-stream.
The global installation of npm appears to have been borked, and are-we-there-yet couldn't resolve access to the readable-stream module for some reason (bad install?).
This wasn't getting fixed by re-installing node, which by default installs npm into program files (path similar to C:\Program Files\nodejs\node_modules\npm). I think the global version was getting run, but the version inside program files should be getting run, so wiping out the global installation of npm should hopefully resolve the issue.
I somehow fixed this issue by upgrading npm in Intellij IDEA.
But I still want an expnalation why that problem in my question happened. I will not mark this as the answer.
No need to uninstall node js. When I tried to update my node version, I got this issue & resolved the the same by following below step -
Go to control panel --> uninstall Programs --> select node.js
and click repair.
Had this issue on a Mac. I cloned a project multiple times to handle different branches in parallel. Only one of my cloned repos started having this same issue when I ran npm start. I deleted the repo, cloned it again and nom was running fine again in that repo. Doesn't sound like a global issue to me. No idea what went wrong.

cannot find module 'config-chain'

This is my first post, so forgive me for formatting issues. I was following this mean.io tutorial: https://www.youtube.com/watch?v=0aMNWYpG5sk. It basically gets you to the point where you can locally access the default web app. I was able to do so successfully.The video then suggests to run>
mean package myTheme
I received this error...
C:\Users\****\myApp>mean package myTheme
module.js:339
throw err;
^
Error: Cannot find module 'config-chain'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (C:\Users\****\AppData\Roaming\npm\node_modules\mean-cli\node_modules\npm\lib\config\core.js:2:10)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
I'm running npm 2.14.7 and node v4.2.3(video uses 4.2.2) on Win 10. I had previously tried this on node 5.3 and received the same error. I also tried cleaning cache & updating npm, bower, and gulp.
I found C:\Users****\myApp\node_modules\config-chain. Do I need to change something here?
Any help would be greatly appreciated. If I need to provide more information, just ask. Thanks!
I guess something was wrong with mean-cli.
I reran:
npm install -g mean-cli
npm install (inside project folder)
My issue was resolved. Hope this helps someone else.
I just removed and re-installed and everything worked. Go figure. I also had to use sudo because I'm on a mac.
sudo npm install -g ember-cli#2.5
The problem is when you install config-chain it installs in your project directory node_modules but cordova add browser is looking in global modules. This is what I did, went outside the directory and ran npm install -g config-chain That resolved this module and asked for more do the same thing for all modules it complains and you should be good.

What's wrong with my typescript compiler? `tsc --version` returns nothing

In Linux Mint, I've installed node and used it to install typescript. With a working typescript installation, tsc --version should return the version number. In my case, nothing is returned at all.
When I run which tsc the result is /usr/local/bin/tsc.
When I run cat /usr/local/bin/tsc the result is:
#!/usr/bin/env node
require('../lib/tsc.js')
When I run find /usr/local -name 'tsc*' the result is:
/usr/local/bin/tsc
/usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/lib/node_modules/typescript/lib/tsc.js
Does that look correct? If so, then any ideas on what else to look at would be appreciated?
Note I also tried running /usr/local/lib/node_modules/typescript/bin/tsc --version and got the same result ie nothing.
In my case on Ubuntu 16.04 the problem was because of I performed sudo apt-get install node-typescript, which delivered me broken tsc. After removing it via apt-get remove and then installing as recommended with npm install -g typescript, it worked fine.
Maybe this will help someone.
I discovered that running node --version returns nothing (but shouldn't) however nodejs --version works (the result being v0.10.25). Reinstalling node didn't fix this. I don't know why this would be the case, as I think I followed the recommended installation procedure.
However, editing file /usr/local/bin/tsc and changing the line:
#!/usr/bin/env node
to
#!/usr/bin/env nodejs
seemed to work. Now tsc --version returns message TS6029: Version 1.6.2 and I'm getting .js files generated when I run make.
I was getting the following error in Ubuntu 16.04.6 :
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'typescript/tsc.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/bin/tsc:2:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Running : npm install -g typescript didn't resolved the issue.
So, I had to install the latest version of node i.e nvm install <nvm version>
Then with npm install , it fixed the issue.

Installing MEAN Stack: npm -v module.js: 338 throw err; Error: Cannot find module './cache/caching-client.js'

I think I have installed node.js before but never used homebrew to do it. Today I tried to do a walkthrough of an application but got stuck at the very beginning. I am fairly new to programming so I am utterly confused as to why I can't get this to work.
I have tried a lot of things but can't seem to find the answer.
These are the commands I run in order to install the MEAN stack:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(succesful no errors)
brew install node
(succesfull no errors)
I check if node has installed properly by typing:
node -v
v0.12.4
I then check if npm is installed properly by typing:
npm -v
Here is the error message:
module.js:338
throw err;
^
Error: Cannot find module './cache/caching-client.js'
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 /usr/local/lib/node_modules/npm/lib/npm.js:22:24
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:466:3)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
I have installed node in a different way other than using Homebrew and maybe that is messing things up. Please let me know your thoughts.
What I have tried to do so far is uninstall node and reinstall it using this process:
https://gist.github.com/DanHerbert/9520689
Maybe you've already fixed, but the answer might serve others.
I tried what is in the post that Mario linked to in his comment, but it didn't work. It just so happens that my npm is installed at /Users/USERNAME/.node/bin/, so I added the following line in my .bash_profile file: export PATH="$HOME/.node/bin:$PATH".
In my case it was caused by me installing node with root and later with brew (without root).
As a result brew was not able to override the old npm files upon upgrading.
Manually removing the old node installation worked for me.

Resources