Yo unaware of installed generators - npm

I just installed Yeoman and some generators. However, because the /usr/lib folder is protected, I chose to change the prefix of the location where NPM installs its packages.
Right now, everything is getting installed under ~/.node. I also changed my $PATH and added ~/.node/bin. However, when I execute yo <name of generator>, I get the following:
Error node
You don't seem to have a generator with the name node installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 0 registered generators run yo with the `--help` option.
As you can read here, it's telling me there are 0 registered generators, but I installed them correctly (and it completed without errors). I'm able to find the installed generators, for example ~/.node/lib/node_modules/generator-node exists and when I execute the following command:
npm list -g
I can find the generators that I installed (so I assume it isn't a problem with npm).
So I think Yeoman (or Yo to be more precisely) is unaware of the generators being installed in the custom folder, but I haven't found any way to configure this.

In addition to adding it to your path, you should also set a NODE_PATH environment variable. The yeoman/generator code will look there first:
// We tried using NPM to get the global modules path, but it haven't work out
// because of bugs in the parseable implementation of `ls` command and mostly
// performance issues. So, we go with our best bet for now.
if (process.env.NODE_PATH) {
_.compact(process.env.NODE_PATH.split(/[;:]/g)).forEach(this.appendPath, this);
return;
}

Looks like a NODE_PATH issue, try to execute the following command:
echo "export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules" >> ~/.bashrc && source ~/.bashrc^C
Or just type yo doctor to figure out what's happening

Related

Environment variables (zsh terminal) installed through npm on MacOS 12.4 Monterey - SOLVED

Background:
Dear Stackoverflow community. I recently switched from Windows to MacOS and am at a loss how to configure environment variables. Many of the previous questions asked here are about bash instead of zsh.
Goal:
I am trying to install an npm package globally. For instance:
npm install -g vercel
or any other package, and use it in my Visual Studio Code terminal (also zsh). If I want to deploy code I have to use 'npx vercel deploy' every time. I want to be able to use "vercel deploy" but instead I get:
zsh: command not found: vercel
What I tried so far:
Installing the package in zsh and visual studio code terminals (didn't work)
Setting the path equal on both VS and terminal: export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I learned that you need to add environment variabels to a .zshrc file. I don't seem to have a zshrc file. When I do:
sudo ~/.zshrc
Password: XXXXXX
sudo: /Users/vincent/.zshrc: command not found
I am getting another error.
I read in the zsh man file that you should use $HOME/.zshrc instead. Again I am getting the same errors:
vincent#Vincents-MacBook-Air-2 ~ % $HOME/.zshrc
zsh: permission denied: /Users/vincent/.zshrc
vincent#Vincents-MacBook-Air-2 ~ % sudo $HOME/.zshrc
sudo: /Users/vincent/.zshrc: command not found
Update 1:
#slebetman Thank you for your explanation. When I open the terminal I go to home via "cd $HOME" which puts me in in the home directory. However there is no way for me to create a .zshrc file in that directory. Neither via touch or vs code. I am getting the following error: "Unable to write file '/home/.zshrc' (Unknown (FileSystemError): Error: ENOTSUP: operation not supported on socket, open '/home/.zshrc')"
Update 2:
I did manage to find the .zshrc file in visual studio code under /etc. I hope this will work. I was able to overwrite the file with Sudo and add environment variables to it.
Add this to the file .zshrc file under /etc and force overwrite it:
export vercel=/Users/vincent/.npm-global/bin/vercel
Screenshots below for those who will try in the future:
Image with .zshrc file layout
Final remarks:
I don't understand how it is so difficult to add environment variables on Mac while everything else is so easy.
I have read many different questions on stackoverflow, and I can't seem to solve it. Also since I am a newbie I am not allowed to comment on there so I post here in the hope that anyone can help me :)
Best,
Vincent
Note that when you do:
npx vercel deploy
Npm will execute vercel for you without installing it. It does that by temporarily downloading vercel. If you want to run vercel directly without using npx then simply don't use npx. Install it instead:
npm install -g vercel
The -g flag installs the module globally and if the module has a CLI it will be available globally as well (note that depending on your setup you may need admin/sudo privileges to use the -g flag). Now you can run vercel by simply typing:
vercel deploy
This works in all operating systems supported by node.js and npm. That means you can even do this in Windows. In fact I use npm to distribute my tools in a simple cross-platform way so I don't have to support multiple package managers like chocolatey (Windows), homebrew (Mac OS), deb (Debian based distros), rpm (Redhat based distros) etc. (npm does not require your software to be written in node.js - I have published packages on npm written in tcl and bash).

Where does npm store module when loading directly from github?

I have found a react-native module I would like to use. It contains an error which prohibits the installation.
I have forked the repository and corrected the mistake.
Now I want to install my module in order to use it, however during execution of the post installation scripts I get an error - file not found.
I have tried to find the reason for it, but the reason is quite simple, the module is not in the node_modules directory, and when npm tries to "enter" there to run the scripts, it can't find them.
I have tried to check where this is installed, but I can't.
I use npm install <user>/<repo> to install my module.

Can't run npm after installing

I've seen many similar posts on this here on SO but for some reason those solutions don't seem to work for me. Clearly I'm missing something.
I installed depcheck package globally by running npm install -g depcheck which ran fine without any errors.
If I go into the global directory for npm packages which is:
c:\Users\<Username>\AppData\Roaming\npm on my Windows 10 machine, I do see the depcheck.cmd file.
I also see the depcheck folder within c:\Users\<Username>\AppData\Roaming\npm\npm_modules folder.
I think this means I was able to install the depcheck package globally.
When I run npm config get prefix, I get c:\Users\<Username>\AppData\Roaming\npm which seems to be the correct path.
Why is it that when I run depcheck inside my project's root folder where the package.json is located, I get:
'depcheck' is not recognized as an internal or external command,
operable program or batch file
If I try another standard npm command inside my project's root folder, it works fine. For example, I ran npm -v and got the version number.
What am I doing wrong?
I also had this problem before. After searching on the web I found that reinstalling NPM with Administrator permissions worked for me, as the installer without Administrator permissions doesn't create/write to some specific files. I hope this will help for you.
Pascal.

CMake error not providing FindGnuradio.cmake

Getting the following error when running cmake and am unsure how to fix it. It seems like it's telling me exactly what to do, but not very familiar with Linux.
CMake Error at CMakeLists.txt:153 (find_package):
By not providing "FindGnuradio.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Gnuradio",
but CMake did not find one.
Could not find a package configuration file provided by "Gnuradio"
(requested version 3.7.3) with any of the following names:
GnuradioConfig.cmake
gnuradio-config.cmake
Add the installation prefix of "Gnuradio" to CMAKE_PREFIX_PATH or set
"Gnuradio_DIR" to a directory contaning one of the above files. If
"Gnuradio" provides a separate development package or SDK, be sure it has
been installed.
EDIT: So I've located something called FindGnuradioRuntime.cmake but am still unsure what to do with it. The error message makes me think it was looking for something named "FindGnuradio.cmake" when it was actually called "FindGnuradioRuntime.cmake"
Commands that were run on a fresh Ubuntu install:
git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig
git clone git://git.osmocom.org/gr-osmosdr
cd gr-osmosdr/
mkdir build
cd build/
cmake ../ (here is where I ran into a the problem above)
Install / build GNU Radio.
Remove the CMakeCache.txt
When you call cmake .. you can pass arguments. Add the path to the parent directory of GnuradioConfig.cmake or FindGnuRadio.cmake as in
cmake -DCMAKE_PREFIX_PATH=/gnu/radio/path ..
Making my somewhat hidden response an actual answer:
Just found out that the install script provided on GNURadio's website not only installs GNURadio, but also the RTL SDR requirements as well, so I wiped my VM and started over and was successful. It takes a few hours, but it is complete and automated so definitely the best way to install GNURadio. Script is here http://www.sbrac.org/files/build-gnuradio
As previous answers noted you didn't describe where you ran into this problem. I'm going to assume it happened when creating an Out Of Tree (OOT) module.
On the OOT Module Page, see the "Notes" Section. They note that you need to install gr-dev. That package will install GnuradioConfig.cmake. You can find it in the standard yum repos, and install it with sudo yum install gnuradio-devel.

Yeoman can't recognize a generator that was installed globally

I ran sudo npm install -g generator-flask and it was saved. I was able to confirm by running npm list-g.
I then run yo flask. Thinking that this was going to work, I instead get an error message:
Error flask
You don't seem to have a generator with the name flask installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 22 registered generators run yo with the `--help` option.
I do as it tells me by running yo --help and discover that the flask generator is not there.
I try this with sudo npm install -g generator-angular-flask and the problem is recreated with Angular Flask. I'm assuming this is going to happen for all the generators which is why I've titled it as Yeoman not recognizing new npm installs.
Does anyone know why this has happened?
A workaround, but does solve the problem:
npm link generator-angular-flask
(as does just installing the module locally)
Usually it is a $NODE_PATH issue, but rather then guessing, run:
yo doctor
and follow the instructions!
Node path is the issue.
To setup path:
export NODE_PATH=$HOME/.node/lib/node_modules/
In my case node is in HOME directory.
I was having a similar issue. Basically Yeoman was showing No installed generators, even if I fired up yeoman and installed the generator again still no luck to run it.
I typed yo doctor and did the changes it recommends, but still no luck...
I then ran
export NODE_PATH=$HOME/.node/lib/node_modules/
Then I fired up Yeoman and still no luck.
I then decide run yo doctor again and voila! New errors. I then saw the final recommendation by the yo doctor so I decide to run it:
export NODE_PATH=$NODE_PATH:/Users/slickstyles/.npm-global/lib/node_modules
After I type yo and guess what I see? All my installed yeoman generators showing and working marvelously.
You can use:
yo doctor
and you will not something like:
npm root value is not in your NODE_PATH
[Info]
NODE_PATH = /home/action/.node/lib/node_modules/
npm root = /home/action/.parts/lib/node_modules
[Fix] Append the npm root value to your NODE_PATH variable
Add this line to your .bashrc
export NODE_PATH=$NODE_PATH:/home/action/.parts/lib/node_modules
Or run this command
echo "export NODE_PATH=$NODE_PATH:/home/action/.parts/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
and try again:
npm install -g generator-webapp
Check if you have NODE_PATH set. To set it open a terminal and type (assuming you have node under /opt/node/ and use bash shell)
echo "export NODE_PATH=/opt/node:/opt/node/lib/node_modules" >> ~/.bashrc && . ~/.bashrc
Once done, run yo doctor. If all is ok, run yo to see your installed generators.