question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is this plugin must be registered globally?

See original GitHub issue

i read the docs for vue2, and can’t find the locally regisered example, only the globally registered example. so i try it out, and failed. So is this plugin can only be registered globablly, or am i miss something?

i read the issue #1 , it seems related, but i’m using one single version of highlightjs 10.7.2, so i’m not quite clear whether or not this plugin supports locally register.

thanks.

NODE_MODULES


+---@highlightjs
|   \---vue-plugin
|       +---dist
|       \---src
|           \---lib
+---highlight.js
|   +---lib
|   |   \---languages
|   +---scss
|   +---styles
|   \---types

image

GOOD version (Globally registered):

image

<template>
  <div>
    <highlightjs language="javascript" code="var x = 5;" />
  </div>
</template>

<script>
import Vue from 'vue'
import hljs from 'highlight.js/lib/core'
import javascript from 'highlight.js/lib/languages/javascript'
import 'highlight.js/styles/a11y-dark.css'

import hljsVuePlugin from '@highlightjs/vue-plugin'

hljs.registerLanguage('javascript', javascript)
Vue.use(hljsVuePlugin)
export default {
  components: {}
}
</script>

BAD version (Registered in single file component):

image

<template>
  <div>
    <highlightjs language="javascript" code="var x = 5;" />
  </div>
</template>

<script>
import Vue from 'vue'
import hljs from 'highlight.js/lib/core'
import javascript from 'highlight.js/lib/languages/javascript'
import 'highlight.js/styles/a11y-dark.css'

import hljsVuePlugin from '@highlightjs/vue-plugin'

hljs.registerLanguage('javascript', javascript)
// Vue.use(hljsVuePlugin)
export default {
  components: { hljsVuePlugin }
}
</script>

errors in chrome console:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Unknown custom element: <highlightjs> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

found in

---> <TestTarget> at src/views/WebView/SourceCodeViewer.vue
       <TestPage> at src/pages/TestPage.vue
         <App> at src/App.vue
           <Root>

if i give a name,the error message change, but still cannot render the ‘var x = 5’

export default {
  components: { 'highlightjs': hljsVuePlugin }
}
vue.runtime.esm.js?2b0e:619 [Vue warn]: Failed to mount component: template or render function not defined.

found in

---> <Highlightjs>
       <TestTarget> at src/views/WebView/SourceCodeViewer.vue
         <TestPage> at src/pages/TestPage.vue
           <App> at src/App.vue
             <Root>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Jun 18, 2021

The vue2 version exports component also, though Vue 3 version does not. Perhaps that would work?

export default {
  components: { 'highlightjs': hljsVuePlugin.component }
}
0reactions
joshgoebelcommented, Jun 18, 2021

Would mind resolving maybe? 🙃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChartJS unable to register global plugin - Stack Overflow
Plugins must define a unique id in order to be configurable. So i just added the id in my code. Chart.register({ id: 'no_data_label' ......
Read more >
Do not register plugin globally when using module import #377
The actual workaround I found is to unregister the plugin right after the import: import chartJsPluginZoom from 'chartjs-plugin-zoom'; Chart.
Read more >
Plugins | Chart.js
Plugins can be registered globally to be applied on all charts (a.k.a. ... Plugins must define a unique id in order to be...
Read more >
Getting Started - chartjs-plugin-datalabels
Since version 1.x, this plugin no longer registers itself automatically. It must be manually registered either globally or locally (see #42 ...
Read more >
How can I register a global action filter from my plugin in ...
Hi timmit, First you need to implement this interface in your plugin INopStartup and set the order to be some number bigger than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found