Command not found after installing #vue/cli - vue.js

I npm installed #vue/cli with npm install -g #vue/cli. but when I try the vue command I get -bash: vue: command not found. I added export PATH="/usr/local/Cellar/node/11.2.0/lib/node_modules/#vue/cli/bin:$PATH" to my bash profile and when I echo path in terminal I get
/usr/local/opt/openssl/bin:/usr/local/Cellar/node/11.2.0/lib/node_modules/#vue/cli/bin:/Users/jimmymona/.node/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/usr/local:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/usr/local:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Which does have the path to the vue cli in it: /usr/local/Cellar/node/11.2.0/lib/node_modules/#vue/cli/bin
I also tried sudo installing it but that didn't work either
Anyone know what the issue is?

The path is wrong. The binary resides in /usr/local/Cellar/node/11.2.0/bin rather than .../lib/....
As you'll notice, the file in the latter directory is named as vue.js, not vue.
NPM creates a symlink without the .js extension to it in the bin directory, and that's the actual binary we typically refer to.
Typically we don't use the full path in .bashrc directly (in case the npm global path changes).
Rather, it's recommended to calculate it by combining the result of npm config get prefix and /bin, i.e.
export PATH="$PATH:$(npm config get prefix)/bin"

Related

Why can't I run my node packages from the terminal?

Good evening,
I tried installing sails, yo, gulp & bower via the usual methods of npm i -g yo gulp bower etc but each time I open the terminal to run the command I always get the -bash: sails: command not found error.
I listed all my folders at the root of my folder and found the following:
The contents of the .npm-global/bin/ is actually all the packages I'm trying to use at the command line.
I decided to manual add the bin folder to the .bash_profile so it's contents was the following:
# Setting PATH for Python 3.7
# The original version is saved in su
export PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH="/.npm-global/bin:${PATH}"
but that didn't work either.
Here's where I think the problem first arose - I think that the python install overrode all the previous paths in the file (or moved them somewhere perhaps?) so that all previous terminal commands now don't work.
The usual global install for node packages (/usr/local/lib/node_modules/npm/bin) contains the following:
What am I misunderstanding here & how can I fix this?

Is there any difference between installing global packages with Yarn or NPM?

Does it matter whether you install a global package with yarn global add PACKAGE vs npm install -g PACKAGE ?
Is there any difference at all, like where files are installed?
If yes, what is it?
So yes, you are right it is different. For npm it is something like below
/Users/tarunlalwani/.nvm/versions/node/v9.2.0/lib if you are using nvm
You can get this path using
$ npm config get prefix
/Users/tarunlalwani/.nvm/versions/node/v9.2.0
Where does npm install packages?
While yarn uses other paths
Windows: %LOCALAPPDATA%/Yarn/config/global
OSX and Linux non-root: ~/.config/yarn/global
Linux if logged in as root: /usr/local/share/.config/yarn/global
How to display yarn globally installed packages?
See this thread as well
https://github.com/yarnpkg/yarn/issues/2049
This is the document about Yarn global
yarn global is a prefix used for a number of commands like add, bin,
list and remove. They behave identically to their normal versions
except that they use a global directory to store packages. The global
command makes executables available to use on your operating system
and this is the document about npm install global mode
In global mode (ie, with -g or --global appended to the command), it
installs the current package context (ie, the current working
directory) as a global package.
I think there is no difference between them. Install a package as a global useful for developer tooling that is not part of any individual project but instead is used for local commands

Yarn global install of private module

I am trying to install a module globally with yarn.
I typed the following command:
yarn global add react-native-rename
and then I find it in the yarn global directory, and I am able to call it directly since the directory is included in the path.
But if I try to do the same thing with the same cloned repository hosted on my gitlab:
yarn global add git+ssh://git#git.company.info:mobile/react-native-rename.git
the installation goes fine but the binary is not present into the folder.
yarn global list
shows the binaries as installed but I am unable to find it, neither looking for it using which react-native-rename.
Any idea?
Could you try adding this to your .bashrc or .zshrc?
export PATH="$(yarn global bin):$PATH"
Yarn Global docs
https://classic.yarnpkg.com/en/docs/cli/global/
FYI: Locations on my mac
Executable: /usr/local/bin
Location of downloaded code: ~/.config/yarn/global/node_modules
Could you check these two directories?

Installing Bower globally using npm

I am trying to install Bower globally and it is installed in the directory of
C:\Users\{{user}}\AppData\Roaming\npm\node_modules\bower
I have added the system path of Path and NODE_PATH to that of above, however when running bower, it still cant find the modules.
the prefix of npm-config is:
C:\Users\{{user}}\AppData\Roaming\npm
however later within the the list it states it as
"C:\Program Files (x86)\nodejs" (overridden)
Ive run out of ideas of what it could be,
If you using npm, which looks like you are, then use the global flag (run as admin)
npm install -g bower
Sometimes another version or just a wrong path is referenced in the npm config file instead of the installed version.
This may cause node/npm to misplace global modules.
To check and fix:
In cmd line type: npm config list
You should get a list of configuration values, one of them is prefix.
Make sure the path in prefix is the same path (only without node.exe) as the actually installed node.exe path.
(this path is listed further down as node bin location)
If it's not, change it:
Either in the config file (in your user folder, named .npmrc)
Or, via cmd line: npm config set prefix "C:\Program Files\nodejs" (change path if needed)
Reinstall the module/package you tried to install, don't forget -g for global.

babel-cli not working as expected

I had installed babel-cli globally using npm. And I had a script.js file which contains the ES6 code. When I tried to compile that using $babel script.js -o out.js, it just copy all the contains of the script.js to out.js.
As far I concern, it should convert all the ES6 code to ES5.
Even if I run the script.js file without any content, it should show "use strict"; in my out.js. But it shows an empty file. Unable to figure out whats wrong?
Moreover I am unable to understand why "https://www.npmjs.com/package/babel-cli" says to install babel-cli globally where as "https://babeljs.io/docs/setup/#babel_cli" says to install that locally.
When I installed babel-cli locally and try to compile the script.js file it simply shows
'babel' is not recognized as an internal or external command,
operable program or batch file.
This should answer your question worked for me.
https://github.com/babel/babel/issues/4066
or install babel-cli globally and try it works then.
First Go to main directory or open new terminal
step 1: go to main directory
open terminal or (type cd so that you can directly switch in main directory)
step 2 : npm install -g babel-cli
now successfully install babel cli in your machine
npm install -g babel-cli
It works.