new commands are installed but they still don't work - node.js

Friends-MacBook-Pro:~ friend$ npm install -g live-server
/Users/friend/.npm-global/bin/live-server -> /Users/friend/.npm-global/lib/node_modules/live-server/live-server.js
live-server#1.2.0
updated 1 package in 15.078s
Friends-MacBook-Pro:~ friend$ live-server -v
-bash: live-server: command not found
Friends-MacBook-Pro:~ friend$ npm install -g create-react-app
/Users/friend/.npm-global/bin/create-react-app -> /Users/friend/.npm-global/lib/node_modules/create-react-app/index.js
+ create-react-app#1.4.3
added 106 packages in 13.884s
╭─────────────────────────────────────╮
│ │
│ Update available 5.5.1 → 5.6.0 │
│ Run npm i -g npm to update │
│ │
╰─────────────────────────────────────╯
Friends-MacBook-Pro:~ friend$ npm i -g npm
+ npm#1.0.0
added 1 package in 1.566s
Friends-MacBook-Pro:~ friend$ create-react-app newtypelabs.io
-bash: create-react-app: command not found

You should add the bin path to your user environment.
echo 'export PATH="/Users/friend/.npm-global/bin:$PATH"' >> ~/.bash_profile

Related

NPM can not find globally installed packege

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
???

npm linked module listed as unmet dependency

I'm linking my-lib to see effects in my-app right away.
cd my-lib-folder
npm link
cd ../my-app-folder
npm link my-lib
This works as expected. Changes are picked up by my-app and I see the symlink in node_modules. My problem is that in my-app-folder/, npm list --link=true shows up empty. How can I get a list of the linked modules?
npm ls my_lib
my-app#3.1.0 /Users/path/my_project
└── UNMET DEPENDENCY my-lib#3.7.0
npm ERR! missing: my-lib#3.7.0, required by my-app#3.1.0
This happens both with Node 8 and 10 and their respective npm versions.
OK, I realized that my-lib was somehow linked globally
$ npm ls -g --link=true --depth=0
/Users/apth/.nvm/versions/node/v8.11.4/lib
└── my-lib#3.1.0 -> /Users/franzih/code/my-lib-folder
Unlinking it with npm unlink -g my-lib and linking it again worked and it now shows up as local link:
$ npm ls --link=true
my-app#3.1.0 /Users/path/code/my-app-folder
└─┬ my-app#3.7.0 -> /Users/path/.nvm/versions/node/v8.11.4/lib/node_modules/my-lib-folder
├─┬ https-proxy-agent#2.2.1
│ ├─┬ agent-base#4.2.1
│ │ └─┬ es6-promisify#5.0.0
│ │ └── es6-promise#4.2.4
│ └─┬ debug#3.1.0
│ └── ms#2.0.0
└── node-fetch#2.2.0
Now npm i does not overwrite the link anymore. All good.
In my case, "my-lib" was not linked globally, but I had to:
Uninstall it completely from "my-app" (npm uninstall my-lib)
npm link my-lib from "my-app", and then
Run npm install my-lib in "my-app"
Every other combination of steps did not work, and I did not find the uninstall or reinstall documented anywhere. Hope this helps anyone else running into this problem.

NPM - dependencies require package in multiple versions, but only one version is installed

After npm install on clean environment, I get following problem with b package:
npm ls b
a#2.0.6
├── b#3.0.0
├─┬ c#3.0.1
│ └── UNMET DEPENDENCY b#^1.0.0
└─┬ d#4.1.1
└─┬ c#2.1.0
└── UNMET DEPENDENCY b#^1.0.0
npm ERR! missing: b#^1.0.0, required by c#3.0.1
npm ERR! missing: b#^1.0.0, required by c#2.1.0
This obviously causes errors, as package c needs b#^1.0.0, but receives b#3.0.0.
I struggled to force npm to install both versions as if they were different packages. Tried going through npm docs, package-locks, and shinkwrap, but with no success. How can I solve this problem?
Environment info:
OS: macOS High Sierra 10.13.4
npm: 6.10
node: v8.8.1
Playing around I noticed, that a lot of packages had UNMET DEPENDENCY. Following procedure fixed the problem:
rm -rf node_modules
npm cache clean --force
npm install
After cleaning npm cache the issue is completely resolved:
a#2.0.6
├── b#3.0.0
├─┬ c#3.0.1
│ └── b#^1.0.0
└─┬ d#4.1.1
└─┬ c#2.1.0
└── b#^1.0.0
Strange bug.

`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

Resources