#项目是Vue3.0 用的vue-cli4.5
#以下是main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
const app = createApp(App);
app.use(ElementPlus).use(store).use(router).mount('#app')
#控制台报如下错误
ERROR Failed to compile with 1 error 下午9:52:45
error in ./node_modules/async-validator/dist-web/index.js
Module parse failed: Unexpected token (847:18)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| class Schema {
| // ========================= Static =========================
> static register = function register(type, validator) {
| if (typeof validator !== 'function') {
| throw new Error('Cannot register a validator by type, validator is not a function');
@ ./node_modules/element-plus/es/components/form/index.js 6:0-45 453:28-42
@ ./node_modules/element-plus/es/components/index.js
@ ./node_modules/element-plus/es/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://192.168.1.228:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
我也遇到这个问题,降到beta17就可以了,初步查了一下,是element-plus依赖的async-validator版本引起的,现在卸载elementui-plus 重新安装,看一下package-lock.json里面async-validator版本号是不是变成4.0.7了,如果还是4.0.5得话,你就手工改好了。
"async-validator": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.0.7.tgz",
"integrity": "sha512-Pj2IR7u8hmUEDOwB++su6baaRi+QvsgajuFB9j95foM1N2gy5HM4z60hfusIO0fBPG5uLAEl6yCJr1jNSVugEQ=="
},
卸载 element-plus
重新安装,通过 vue add element-plus
来安装
你是不是用了最新的beta20,如果是新项目,改低点就行了