javascript - 找不到命令

标签 javascript npm vue.js vue-cli

一直在努力启动我的第一个 vue 项目,并正在寻求一些帮助。 我在我的系统上同时更新了 npm 和节点,但不断陷入同一个问题。

我的步骤:

1.) npm 安装
终端响应:

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

2.) npm install vue
终端响应:

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

这就是事情变得奇怪的地方?


3.) npm install -g @vue/cli
终端响应:

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

鉴于此响应,我运行


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

终端响应:

/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 创建 vue-project 终端响应:

-bash: vue: command not found

让我有点困惑和困惑,但任何帮助/回应将不胜感激。

最佳答案

我也遇到了这个问题,找到解决方案有点棘手,所以我将描述帮助我找到解决方案的所有步骤。

它解决了 npm 中全局包路径错误或 shell 变量 $PATH 中缺少路径的一般问题。

修复了 macOS Mojave,但应该适用于所有 UNIX 系统

首先,在全局安装包后,npm 将显示新包的安装位置。

$ 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

我们也可以在 npm 配置中查看。

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

因此,如果在全局安装后您的终端无法识别该命令,它可能在您的 shell 变量 $PATH 中丢失了。您可以轻松检查它。

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

正如我们所见,来自 npm config 的路径不存在于 shell 变量 $PATH 中。

现在我们有两种选择来修复它。

<强>1。第一个选项 - 更改 npm 配置

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

在我们更改配置中的路径后,我们将不得不重新安装所需的包。

$ npm i -g @vue/cli

<强>2。第二个选项 - 添加从 npm 配置到 shell $PATH

的路径
$ export PATH=$PATH:/usr/local/Cellar/node/9.5.0

在这种情况下,我们不需要再次安装包。

无论选择什么选项,我们现在都可以控制是否一切正常。

$  vue --version
3.0.5

关于javascript - 找不到命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50259593/

相关文章:

javascript - 如何在 2.0 中获取 vuetify 数据表选定的 itemsPerPage?

javascript - 无法正确加载更少

javascript - jQuery 1.9 浏览器检测

node.js - 有没有办法从 nodejs 代码中的 package.json 获取版本?

node.js - Package.json 指定了 Node 版本,但 Azure 告诉我没有指定

laravel - 我如何设置 Vue 3 + Laravel 8

javascript - 在 v-data-table 中使用标题槽时添加空标题行

javascript - 在动态生成的内容上应用 Shadowbox.js

javascript - 如何在数据绑定(bind)之前和之后触发自定义动画并等待其完成

javascript - 在 Meteor 中上传 POST 提交的图片