多种方式解决 Windows CMD 中 vue-cli-service 不是内部或外部命令

前提

已安装 Vue 脚手架

1
npm install -g @vue/cli

现象

找不到 vue-cli-service 命令

1
'vue-cli-service' is not recognized as an internal or external command, operable program or batch file.

经过搜索,发现这个问题只在 Windows 下存在。

装了脚手架应该会在 node 目录产生 vue-cli-service.cmd 的文件,实际没有产生,不过在全局 node_modules 下是有的。

有说清理 node_modules 重新安装可以解决的,试了不管用,全局卸载脚手架重新安装也不管用,就算管用也比较麻烦,于是我找到了几个间接使用方法——

方法1 - npm run

package.json 中配置启动命令

package.json
1
2
3
4
5
{
"scripts": {
"serve": "vue-cli-service serve"
}
}

然后使用 npm run serve 来代替 vue-cli-service serve

方法2 - npx

命令前加 npx,如

1
2
npx vue-cli-service serve
npx vue-cli-service test:unit

更多关于 npx 介绍见——https://www.ruanyifeng.com/blog/2019/02/npx.html

方法3 - vue ui

  1. 启动图形界面
    1
    vue ui
  2. 访问 http://localhost:8000/ 选择项目文件夹,点任务 - 运行

多种方式解决 Windows CMD 中 vue-cli-service 不是内部或外部命令

https://www.imaegoo.com/2020/vue-cli-service-is-not-recognized/

作者

iMaeGoo

发布于

2020-01-19

更新于

2020-01-19

许可协议

CC BY 4.0

评论