问题描述
我将2017 MacBook Pro与Catalina(10.15.3)结合使用,并安装了最新版本的node(v12.18.3)和npm(6.14.6),但是当我运行命令npm install -g @vue/cli
时,我得到了以下消息:
npm WARN deprecated @hapi/[email protected]: joi is leaving the @hapi organization and moving back to 'joi' (https://github.com/sideway/joi/issues/2411)
npm WARN deprecated [email protected]: request has been deprecated,see https://github.com/request/request/issues/3142
npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and Could be using insecure binaries. Upgrade to fsevents 2.
/Users/MYUSERNAME/npm/bin/vue -> /Users/MYUSERNAME/npm/lib/node_modules/@vue/cli/bin/vue.js
npm WARN @vue/[email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
+ @vue/[email protected]
added 3 packages from 2 contributors and updated 2 packages in 95.885s
此后,当我运行vue --version
时收到消息-bash: vue: command not found
我已经阅读了很多论坛,并尝试了多种安装方式,例如,使用sudo
,运行sudo chown -R MYUSERNAME:/usr/local/lib/node_modules
以及再次尝试npm install -g @vue/cli@latest
等;而且我什至完全卸载并重新安装了node和npm,但没有任何作用
我该怎么办?
解决方法
经过2天的挫折,这帮助我解决了问题:
How to fix the terminal error: vue command not found (MacOS)
提示:您还可以转到用户帐户的Home Finder窗口,查看隐藏的文件夹(Command + Shift +。),并使用文本编辑器编辑.bash_profile,以遵循本文中的建议。查找“ $ username-> npm-> bin”文件夹,在其中应该看到一个vue.js文件。这是vue-cli安装到的文件夹
, Node(v15.0.1)和npm v7.0.5的“当前”版本允许在macOS Catalina上成功安装@vue/cli
。
从nodejs.org下载最新的“当前” macOS Installer (.pkg)
,然后尝试一下。如果您使用nvm
,请将以下代码添加到.bashrc
或.bash_profile
中。
注意:在Catalina上,默认外壳程序为zsh
,因此您应将以下内容添加到.zshrc
。
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
,
如果你没有正确版本的npm,它会显示这种错误
所以class _SomeState extends State<SomeWidget> {
final textController = TextEditingController();
@override
void dispose() {
textController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(children: [
TextField(controller: textController),TextButton(
onPressed: () {
textController.text += '123';
},child: Text('Button')
),]);
}
}
然后Npm install -g npm@latest
执行此操作后尝试安装 vue.js npm install