gluons / vue-highlight.js

📜 Highlight.js syntax highlighter component for Vue.
https://git.io/vue-highlight.js
MIT License
208 stars 24 forks source link

Using with Vue 3.0 #72

Closed Somfic closed 10 months ago

Somfic commented 3 years ago

Is there a way to use this package with Vue 3?

import { createApp } from "vue";
import App from "./App.vue";
import "bootstrap/dist/css/bootstrap.min.css";
import router from "./router";

import VueHighlightJS from "vue-highlight.js";
import json from "highlight.js/lib/languages/json";
import "highlight.js/styles/default.css";

createApp(App)
    .use(router)
    .use(VueHighlightJS, { languages: json })
    .mount("#app");

Results in

Uncaught TypeError: Object prototype may only be an Object or null: undefined
    at setPrototypeOf (<anonymous>)
    at extendStatics (tslib.es6.js?9ab4:21)
    at __extends (tslib.es6.js?9ab4:25)
    at eval (vue-highlight.es.js?c964:350)
    at eval (vue-highlight.es.js?c964:413)
    at Module../node_modules/vue-highlight.js/dist/vue-highlight.es.js (chunk-vendors.js:1396)
    at __webpack_require__ (app.js:854)
    at fn (app.js:151)
    at eval (main.js:15)
    at Module../src/main.js (app.js:1122)
CMCDragonkai commented 3 years ago

I'm interested in this, but I don't get TypeError. I'm getting warnings like:

WARNING in ./node_modules/vue-highlight.js/dist/vue-highlight.es.js 21:28-31
export 'default' (imported as 'Vue') was not found in 'vue' (possible exports: BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compile, computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, inject, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toDisplayString, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId)
 @ ./src/index.ts 7:43-70

WARNING in ./node_modules/vue-highlight.js/dist/vue-highlight.es.js 413:2-5
export 'default' (imported as 'Vue') was not found in 'vue' (possible exports: BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compile, computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, inject, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toDisplayString, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId)
 @ ./src/index.ts 7:43-70
CMCDragonkai commented 3 years ago

That's the compilation errors, but the errors from using the library when loading does result in what @Somfic said.

ddzy commented 3 years ago

Any progress?

ajmueller commented 3 years ago

For those who need something that works with Vue 3, I'd suggest checking out highlightjs/vue-plugin. It works well.

F-one-1 commented 2 years ago

it may work OK in v4 with Vue 3.