簡體   English   中英

無法使用 npm 在 macos 上安裝 vue

[英]unable to install vue on macos using npm

有幾個步驟:

  1. 使用節點 v10+ 而不是 v14+。

  2. (IMPT) 將以下路徑添加到~/.zshrc (如果你使用的是 zsh)

/Users/[yourUsername]/.npm-packages/bin

/Users/[yourUsername]/.npm-global/bin

  1. 修改文件后運行source ~/.zshrc

非常感謝@kissu@Lakindu Hewawasam !!

--------原始問題-----

我使用的是 MacOS 10.15.5,節點版本 v14.15.4,npm 版本 6.14.10。

在嘗試了多種下載 Vue 的方法后,我一直收到錯誤zsh: command not found: vue

我首先嘗試npm install -g @vue/cli ,它給了我這個錯誤,所以我卸載並再次嘗試sudo npm install -g @vue/cli @vue/cli-init --unsafe-perm指的是這個. 仍然,它不起作用:

yingjieqiao@Yingjies-MacBook-Pro ~ % sudo npm install -g @vue/cli @vue/cli-init --unsafe-perm
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated vue-cli@2.9.6: This package has been deprecated in favour of @vue/cli
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)

> yarn@1.22.10 preinstall /Users/yingjieqiao/.npm-global/lib/node_modules/@vue/cli/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)

/Users/yingjieqiao/.npm-global/bin/vue -> /Users/yingjieqiao/.npm-global/lib/node_modules/@vue/cli/bin/vue.js

> fsevents@1.2.13 install /Users/yingjieqiao/.npm-global/lib/node_modules/@vue/cli/node_modules/fsevents
> node install.js

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node

> core-js@3.8.2 postinstall /Users/yingjieqiao/.npm-global/lib/node_modules/@vue/cli/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> @apollo/protobufjs@1.0.5 postinstall /Users/yingjieqiao/.npm-global/lib/node_modules/@vue/cli/node_modules/@apollo/protobufjs
> node scripts/postinstall


> nodemon@1.19.4 postinstall /Users/yingjieqiao/.npm-global/lib/node_modules/@vue/cli/node_modules/nodemon
> node bin/postinstall || exit 0


> ejs@2.7.4 postinstall /Users/yingjieqiao/.npm-global/lib/node_modules/@vue/cli/node_modules/ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)

npm WARN @vue/compiler-sfc@3.0.5 requires a peer of vue@3.0.5 but none is installed. You must install peer dependencies yourself.

+ @vue/cli@4.5.9
+ @vue/cli-init@4.5.9
added 1367 packages from 714 contributors and updated 1 package in 43.692s
yingjieqiao@Yingjies-MacBook-Pro ~ % vue --version
zsh: command not found: vue
yingjieqiao@Yingjies-MacBook-Pro ~ % npm update -g @vue/cli

yingjieqiao@Yingjies-MacBook-Pro ~ % vue --version
zsh: command not found: vue
yingjieqiao@Yingjies-MacBook-Pro ~ %

在警告消息中,它多次提到“xxx package will break on node v14+”。 但我認為官方文檔中的下載命令無論如何都應該有效?

根據我的經驗, node版本10.23.0最適合我自己。 所以我推薦使用這個,因為我已經使用10.23.0版本解決了這樣的錯誤。

在這里下載: https://nodejs.org/dist/latest-v10.x/

然后,一旦你安裝了這個版本的節點,運行命令$ npm install vue

您不應安裝任何帶有sudo前綴的 package。
順便說一句,您的節點版本是如何通過nvm或手動安裝的?
也許嘗試用yarn安裝它。

最好的想法可能是回滾並嘗試以推薦的方式調試問題。 也許深入研究 github repo 上的具體問題。

順便說一句,您引用的帖子是舊帖子,因此兩者之間可能發生了變化。

我在Linux上運行以下版本( @vue/cli 4.5.9也很好,只是升級了)。

在此處輸入圖像描述

編輯:另外,這篇文章可能會有所幫助。

尋找其他答案下方的評論,您可以嘗試添加這些

export PATH="$PATH:$(yarn global bin)"
export PATH="$PATH:$HOME/.npm-global/bin"

到您的~/.zshrc文件,因為 vue-cli 顯然已正確安裝。

Ofc,在嘗試再次調用 CLI 之前獲取source ~/.zshrc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM