Svelte Highlight issue with Sveltekit

2023-02-17

Issue

Was having an issue where I was getting an module is not defined error when trying to use the svelte-highlight for rendering code blocks.

Resolution

Found a Github issue [1] where it was resolved and the culprit was vite not being able to locate the highlight.js/lib/core to optimize the code. The problem was also because I’m not using npm or yarn , but instead using pnpm which doesn’t flatten the dependencies, which was causing an issue.

The solution was just to simply install highlight.js as a dependency to the project.

>pnpm i highlight.js

Reference

[1] https://github.com/metonym/svelte-highlight/issues/158