FIameCaster / prism-code-editor

Lightweight, extensible code editor component for the web using Prism
https://prism-code-editor.netlify.app
MIT License
43 stars 6 forks source link

Language 'javascript' has no grammar #33

Closed uetkaje closed 1 day ago

uetkaje commented 1 day ago

Hi,

I try to use Prism code editor in Qwik app. It occurs grammar error for java script while editor initializing.

Simple example on Stackblitz.

Any solution?

Thanks, Emre

FIameCaster commented 1 day ago

The reason this is happening is because the Prism grammar is not included in the JavaScript sent to the client. It seems like only modules referenced in the useVisibleTask$ callback are included in the client bundle. Since the Prism grammar isn't referenced here, it won't be included in the chunk sent to the browser. One way to fix this is create another module that is dynamically imported in useVisibleTask$.

useVisibleTask$(() => {
  import('./addWebComponent');
});

In addWebComponent.ts, include the same code that's in useVisibleTask$ from your example, and import the Prism grammar. This isn't a great solution though since the editor will load slower. I haven't used Qwik, and there might be a better solution for defining what to run in the browser.

uetkaje commented 1 day ago

It works. Thank you so much.