【问题标题】:unable to install vue on macos using npm无法使用 npm 在 macOS 上安装 vue
【发布时间】:2021-01-05 11:52:59
【问题描述】:

有几个步骤:

  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 指的是this。还是不行:

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 包将在节点 v14+ 上中断”。但是我认为官方文档中的下载命令无论如何都应该有效?

【问题讨论】:

    标签: javascript node.js vue.js npm


    【解决方案1】:

    寻找其他答案下方的 cmets,您可以尝试添加那些

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

    到您的 ~/.zshrc 文件,因为 vue-cli 显然已正确安装。

    Ofc, source ~/.zshrc 在尝试再次调用 CLI 之前。

    【讨论】:

      【解决方案2】:

      根据我的经验,node 版本 10.23.0 最适合我自己。所以我推荐使用这个,因为我已经使用版本10.23.0解决了这样的错误。

      在此处下载:https://nodejs.org/dist/latest-v10.x/

      然后,一旦你安装了这个版本的节点,运行命令$ npm install vue

      【讨论】:

      • 您好,感谢您的回复。我已经卸载了 node 并重新安装了 10 版,这次安装没有错误,但仍然有一些警告消息。我尝试运行npm install -g @vue/clinpm install vue 但它仍然给我zsh: command not found: vue 完整输出在这里:docs.google.com/document/d/…
      • 所以你的电脑里有 vue 模块
      • 也许我们可以检查一下vue命令是否添加到路径中
      • 因为你在 Mac 上试试这个命令 - sudo npm install -g @vue/cli
      • 然后运行vue create first-vue-app
      【解决方案3】:

      您不应安装任何带有 sudo 前缀的软件包。
      顺便说一句,您的节点版本是如何通过nvm 或手动安装的?
      也许尝试使用yarn 安装它。

      最好的办法可能是回滚并尝试在recommended way 上调试问题。也许在 github repo 上深入研究具体问题。

      顺便说一句,您引用的帖子是旧帖子,因此两者之间可能发生了变化。

      我在 Linux 上运行以下版本(@vue/cli 4.5.9 也可以,只是升级了)。

      编辑:另外,这个post 可能会有所帮助。

      【讨论】:

        猜你喜欢
        • 2018-07-13
        • 2018-03-02
        • 2021-12-28
        • 2020-02-26
        • 2021-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多