3
<script>
 import * as Vue from 'vue'
import Component from 'vue-class-component'

@Component
export default class HelloWorld extends Vue {
  //my operation
}

</script>

It's a simple example for vue-class-component. However, when I run my project, the browser shows the following error:

Uncaught TypeError: Class extends value #<Object> is not a constructor or null
at eval (HelloWorld.vue?e90b:39:1)
at Module../node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/HelloWorld.vue?vue&type=script&lang=js (app.js:19:1)
at __webpack_require__ (app.js:315:33)
at fn (app.js:570:21)
at eval (HelloWorld.vue?vue&type=script&lang=js:5:213)
at Module../src/components/HelloWorld.vue?vue&type=script&lang=js (app.js:162:1)
at __webpack_require__ (app.js:315:33)
at fn (app.js:570:21)
at eval (HelloWorld.vue:3:97)
at Module../src/components/HelloWorld.vue (app.js:140:1)

Why does this happen? and the cmd also shows such a warning:

in ./node_modules/vue-class-component/dist/vue-class-component.esm.js
export 'default' (imported as 'Vue') was not found in 'vue' (possible exports: BaseTransition, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, compile, computed, createApp, createBlock, createCommentVNode, createElementBlock, createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isShallow, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId)

I'm confused that is any problem with my version about vue-class-component ? What should I do… ?

0

2 Answers 2

7

Component doesn't support in Vue3. So instead of Component you can use Options and if there is any Component you can define them in Options. I also faced same issue so I tried importing Vue from vue-class-component because here Vue is declared as Vue Constructor and export that.

<script>

import {Vue,Options} from 'vue-class-component'
@Options({
    components: {}
})
export default class HelloWorld extends Vue {
  //my operation
}

</script>
Sign up to request clarification or add additional context in comments.

Comments

3

vue-class-component library is currently only available for Vuejs 2. There is an alternative for Vuejs 3 which is called vue-facing-decorator you can find the github page here and the documentation here.

2 Comments

vue-facing-decorator has worked well for us in migrating our class components to Vue 3! In their deprecation notices, vue-class-component and vue-property-decorator both suggest vue-facing-decorator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.