[vue] 解決'vue' 不是內部或外部命令,也不是可運行的程序 或批處理文件的方法

window cmd 下出現 'vue' 不是內部或外部命令,也不是可運行的程序 或批處理文件。的解決方法:

1.查看npm安裝的所在位置 prefix = "C:\\Users\\Administrator\\AppData\\Roaming\\npm"

C:\Users\Administrator\Desktop>npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.4.1 node/v10.15.1 win32 x64"

; builtin config undefined
prefix = "C:\\Users\\Administrator\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Users\Administrator\Desktop
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

自行查看環境變量,沒有的話,需要把npm所在目錄路徑配置到系統環境變量中。

2.進入到npm所安裝的文件目錄,查看是否有vue.cmd文件

3.沒有的話 桌面下cmd 執行cli的全局卸載 全局卸載:npm uninstall vue-cli -g;

4.最後再執行一遍全局安裝:cnpm install -g @vue/cli;, 會發現npm安裝的目錄下出現了 vue.cmd文件 (這裏需要注意,npm 安裝報錯的話,使用cnpm安裝),執行npm install vue-cli -g的話,可能會出現以下提示:

D:\projects\demo>vue create demo

  vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6.
  You may want to run the following to upgrade to Vue CLI 3:

  npm uninstall -g vue-cli
  npm install -g @vue/cli

5.最後 cmd 執行 vue -V,驚喜的發現,出現了vue 的版本號了

執行vue create demo時,有可能又出現問題了Vue和vue-template-compiler版本之間的問題

- vue@2.6.8 (C:\Users\Administrator\node_modules\_vue@2.6.8@vue\dist\vue.runtime.common.js)
- vue-template-compiler@2.6.10 (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\_vue-template-compiler@2.6.10@vue-template-compiler\package.json)

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

這時,在npm安裝的根目錄下,打開cmd, 執行cnpm install [email protected] --save, 使[email protected]版本與[email protected]版本相同

C:\Users\Administrator\AppData\Roaming\npm>cnpm install vue@2.6.10 --save
√ Installed 1 packages
√ Linked 0 latest versions
√ Run 0 scripts
√ All packages installed (1 packages installed from npm registry, used 426ms(network 420ms), spe ed 60.92kB/s, json 1(25.59kB), tarball 0B)

最後執行vue create demo, 出現以下界面, 代表成功了

Vue CLI v3.9.3
? Please pick a preset: (Use arrow keys)
> ant disign (vue-router, vuex, stylus, babel, eslint)
  default (babel, eslint)
  Manually select features

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章