Command not found

我只是一个虾纸丫 提交于 2021-02-10 16:05:48

问题


Been struggling to get my first vue project started and was looking for some help. I have both npm and node updated on my system but continually keep falling to the same issue.

My steps:

1.) npm install
Terminal Response:

npm WARN mbasile@1.0.0 No description
up to date in 0.095s

2.) npm install vue
Terminal Response:

npm WARN mbasile@1.0.0 No description + vue@2.5.16
updated 1 package in 0.951s

Here's where things get funky?


3.) npm install -g @vue/cli
Terminal Response:

npm ERR! path /Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rmdir
npm ERR! Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'
npm ERR! { Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rmdir',
npm ERR! path: '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin' },
npm ERR! stack: 'Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rmdir',
npm ERR! path: '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mbasile/.npm/_logs/2018-05-09T17_53_06_030Z-debug.log

So given this response I run


4.) sudo npm install -g @vue/cli

Terminal Response:

/Users/mbasile/.npm-global/bin/vue -> /Users/mbasile/.npm-global/lib/node_modules//bin/vue.js
+ @3.0.0-beta.9
updated 1 package in 6.597s

5.) vue create vue-project Terminal Response:

-bash: vue: command not found

Leaving me a bit puzzled and confused here, but any help/response would be appreciated.


回答1:


I had this problem too and it was a little bit tricky to find a solution so I'll describe all the steps that helped me find a solution.

It's resolving a general problem with the wrong path for global packages in npm or missing path in shell variable $PATH.

Fix for macOS Mojave but should work on all UNIX systems

First of all, after installing the package globally npm will show you where a new package is installed.

$ npm i -g @vue/cli
/usr/local/Cellar/node/9.5.0/bin/vue -> /usr/local/Cellar/node/9.5.0/lib/node_modules/@vue/cli/bin/vue.js

We can also check it in the npm config.

$ npm config get prefix
/usr/local/Cellar/node/9.5.0

So if after the global installation your terminal couldn't recognize the command it's probably missing in your shell variable $PATH. You can easily check it.

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

As we can see, the path from npm config isn't present in the shell variable $PATH.

Now we have two options to fix it.

1. First option - change npm config.

$ npm config set prefix '/usr/local'
$ npm config get prefix
/usr/local

After we changed the path in the config we will have to reinstall the desired package.

$ npm i -g @vue/cli

2. Second option - add path from npm config to shell $PATH

$ export PATH=$PATH:/usr/local/Cellar/node/9.5.0

In this case, we don't need to install the package again.

Regardless of the selected option, we can now control if everything works.

$  vue --version
3.0.5



回答2:


Maybe it is something wrong with npm

I recommend you,first list all global npm packages to see if vue is installed with the command: npm list -g --depth=0

Then if vue is installed but again you get error try to delete vue with the command: npm uninstall -g nameOfPackage

Finally do it again from scratch: npm install -g @vue/cli and to create new project,navigate to directory you want to create the project and execute: vue create nameOfProject




回答3:


What are you trying to do?

npm install -g @vue/cli

This is the command you should run on terminal to globally (-g) install vue command line interface. After that you can do vue create vue-project



来源:https://stackoverflow.com/questions/50259593/command-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!