NPM can not find globally installed packege - node.js

I've installed everything with homebrew on my mac.
$ which node
/opt/homebrew/bin/node
$ which npm
/opt/homebrew/bin/npm
$ npm -g ls
/opt/homebrew/lib
├── #unlighthouse/cli#0.4.9
├── npm#9.4.0
├── prisma#4.9.0
├── puppeteer#19.6.3
└── ts-node#10.9.1
but when I try to run
npx unlighthouse ...
It fails:
Failed to find a chrome / chromium binary to run.
Add the puppeteer dependency to your project to resolve.
Run the following: npm install -g puppeteer
it seems npm can't access/find globally installed package puppeteer
???

Related

Can't uninstall a package using npm?

Why is npm uninstall -g not uninstalling a package?
$ which flourish
/Users/me/.nvm/versions/node/v8.3.0/bin/flourish
$ which npm
/Users/me/.nvm/versions/node/v8.3.0/bin/npm
$ npm uninstall -g flourish
up to date in 0.056s
$ flourish
😱 No command specified. Type ‘flourish help’ for help.
Local uninstall doesn't help either:
$ npm uninstall flourish
up to date in 1.266s
$ flourish
😱 No command specified. Type ‘flourish help’ for help.
Update - after doing the above:
$ npm -g ls --depth=0
/Users/me/.nvm/versions/node/v8.3.0/lib
...
├── #flourish/sdk#3.6.0
├── #mapbox/geojson-area#0.2.2
├── #mapbox/geojson-merge#1.0.2

`npm install` doesn't install anything?

➜ eslinta git:(master) ✗ npm install eslint --save-dev
eslinta#1.0.0 /Users/next/es6/jsmodules/eslinta
└─┬ eslint#3.15.0
├─┬ babel-code-frame#6.22.0
│ └── js-tokens#3.0.1
├─┬ chalk#1.1.3
│ ├── ansi-styles#2.2.1
...
npm WARN eslinta#1.0.0 No description
npm WARN eslinta#1.0.0 No repository field.
➜ eslinta git:(master) ✗ eslint -v
zsh: command not found: eslint
➜ eslinta git:(master) ✗
What's the reason of this problem?
I installed node by nvm.
Command line modules are installed in a project at ./node_modules/.bin so you can run eslint directly with ./node_modules/.bin/eslint. The better approach is to create a script entry in your package.json:
"scripts": {
"lint": "eslint"
}
because running commands from the scripts entry in package.json will automatically add ./node_modules/.bin to the path. This way you can run your lint with npm run lint
Did you try installing eslint globally?
npm install -G eslint eslinta#1.0.0

mongodb kerberos peer dependency

Trying to install mongodb or mongoose globally results in a missing peer dependency for Kerberos
Jamess-MacBook-Pro:ka2 jamessherry$ npm install -g mongodb
/usr/local/lib
└─┬ mongodb#2.0.48
└── UNMET PEER DEPENDENCY kerberos#~0.0
npm WARN EPEERINVALID mongodb-core#1.2.21 requires a peer of kerberos#~0.0 but none was installed.
Jamess-MacBook-Pro:ka2 jamessherry$ npm install -g mongodb
- nan#2.0.9 node_modules/mongodb/node_modules/kerberos/node_modules/nan
- kerberos#0.0.17 node_modules/mongodb/node_modules/kerberos
/usr/local/lib
└─┬ mongodb#2.0.48
└── UNMET PEER DEPENDENCY kerberos#~0.0
npm WARN EPEERINVALID mongodb-core#1.2.21 requires a peer of kerberos#~0.0 but none was installed.
Jamess-MacBook-Pro:ka2 jamessherry$ npm install -g mongoose
/usr/local/lib
└─┬ mongoose#4.2.5
├── async#0.9.0
├── bson#0.4.19
├── hooks-fixed#1.1.0
├── kareem#1.0.1
├─┬ mongodb#2.0.48
│ ├── es6-promise#2.1.1
│ ├── UNMET PEER DEPENDENCY kerberos#~0.0
│ ├── mongodb-core#1.2.21
│ └─┬ readable-stream#1.0.31
│ ├── core-util-is#1.0.1
│ ├── inherits#2.0.1
│ ├── isarray#0.0.1
│ └── string_decoder#0.10.31
├── mpath#0.1.1
├── mpromise#0.5.4
├─┬ mquery#1.6.3
│ ├── bluebird#2.9.26
│ └── debug#2.2.0
├── ms#0.7.1
├── muri#1.0.0
├── regexp-clone#0.0.1
└── sliced#0.0.5
npm WARN EPEERINVALID mongodb-core#1.2.21 requires a peer of kerberos#~0.0 but none was installed.
Does anyone know how to go about fixing that? If you manually install then you have to do that on every update.
Also, I can't find a place to report the bug...
I just had to run npm install --save kerberos mongodb to successfully install mongodb in my project. I assume you can do it globally as well, but there may be other issues.
From the mongodb NPM package docs:
The kerberos package is a C++ extension that requires a build
environment to be installed on your system. You must be able to build
node.js itself to be able to compile and install the kerberos module.
Furthermore the kerberos module requires the MIT Kerberos package to
correctly compile on UNIX operating systems. Consult your UNIX
operation system package manager what libraries to install.
It goes on to offer the following steps for diagnosing the issue on UNIX-based operating systems:
If you don’t have the build essentials it won’t build. In the case of linux you will need gcc and g++, node.js with all the headers and python. The easiest way to figure out what’s missing is by trying to build the kerberos project. You can do this by performing the following steps.
git clone https://github.com/christkv/kerberos.git
cd kerberos
npm install
If all the steps complete you have the right toolchain installed. If you get node-gyp not found you need to install it globally by doing.
npm install -g node-gyp
If correctly compiles and runs the tests you are golden. We can now try to install the mongod driver by performing the following command.
cd yourproject
npm install mongodb --save
If it still fails the next step is to examine the npm log. Rerun the command but in this case in verbose mode.
npm --loglevel verbose install mongodb
This will print out all the steps npm is performing while trying to install the module.
Other possible issues:
Your python installation might be hosed making gyp break. I always recommend that you test your deployment environment first by trying to build node itself on the server in question as this should unearth any issues with broken packages (and there are a lot of broken packages out there).
Another thing is to ensure your user has write permission to wherever the node modules are being installed.
#!/bin/bash
#My quasi bash script. This worked for Ubuntu v14.04 using Node.js v5.1.0 and mongodb v3.0.7
clear
# prerequisites for building node.js from its source files
sudo apt-get install clang-3.5 make gcc g++ libssl-dev libkrb5-dev
# where you extracted the latest stable release. https://github.com/nodejs/node/releases
cd ~/Downloads/node
# git clone https://github.com/nodejs/node # this does NOT work because it gets a beta/pre release.
./configure
# "-j 3" uses two processors for the compile on a duo core processor. 3 means 2 for some reason.
make -j 3
sudo make install
make doc
make test
# prerequisites for being able to use '$ npm install mongodb'
cd ~
sudo npm install -g node-gyp
sudo npm install -g kerberos
# npm mongodb will NOT install globally '-g'. Therefore you have to install local to each project.
#cd to/your/project/directory
# make sure you are in your project directory root and that the "node_modules" directory is not 'root:root'
npm install mongodb --save

Error when installing Grunt

Hello I recently tried installing grunt-command line interface according to the instructions on their website using the node package manager command
sudo npm install -g grunt-cli
It didnt work and I got the following errors
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/couch-login requires request#'~2.9.202' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/request,
npm WARN unmet dependency which is version 2.30.0
grunt-cli#0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.5)
└── findup-sync#0.1.3 (lodash#2.4.1, glob#3.2.11)
➜ ~
I'm not sure how i update this dependancy. Can anyone shed any light on this?
Try the following:
npm cache clean
npm install -g npm (update npm)
reinstall node.js completely (if all fails).
Please let me know if this works.

Unable to install packages through npm

Installing packages via npm shows the following message and nothing is installed..
sakthiganesh#ubuntu:~$ npm install express
express#2.3.8 ./node_modules/express
├── mime#1.2.2 ()
├── connect#1.4.1 ()
└── qs#0.1.0
any solutions ?
Express are installed already in your case. By default npm installs modules in the node_modules subdirectory of the current dir. If you want to install module globally use commands with -g key:
sudo npm install -g express
But good practice are placing modules required for your application in the application directory. Go to directory, where your javascript file took place and run npm install without -g:
cd /var/www/my_app
npm install express

Resources