先阐述一下环境吧,新手,新环境
node -v
v14.16.1
npm -v
6.14.12
vue -V
@vue/cli 4.5.13
直接跑一个vue组件,正常的命令是这样的
vue serve src/components/demo1.vue
输出提示:
Command vue serve requires a global addon to be installed.
Please run npm i -g @vue/cli-service-global and try again.
再次安装
npm i -g @vue/cli-service-global
再次执行命令
INFO Starting development server…
(node:8312) UnhandledPromiseRejectionWarning: Error: Cannot find module ‘@vue/compiler-sfc/package.json’
再次安装
npm install -g @vue/compiler-sfc
npm WARN @vue/compiler-sfc@3.0.11 requires a peer of vue@3.0.11 but none is installed. You must install peer dependencies yourself.
@vue/compiler-sfc@3.0.11
added 42 packages from 69 contributors in 6.535s
再次启动:)
WARNING Compiled with 1 warning 下午12:06:50
warning in D:/nodejs/node_global/node_modules/@vue/cli-service-global/template/main.js
"export ‘default’ (imported as ‘Vue’) was not found in ‘vue’
因为用的@vue/cli 4.5.13,而cli-service-global的写法时vue-cli 3.x的写法,所以,更改 cli-service-global的模板
D:\nodejs\node_global\node_modules@vue\cli-service-global\template\main.js
改为vue/cli 4.x的写法
import { createApp } from 'vue';
import App from '~entry'
createApp(App).mount('#app');
这回终于可以了
入门学习中…