metonym / svelte-highlight

Syntax Highlighting for Svelte using highlight.js
https://svhe.onrender.com
MIT License
252 stars 13 forks source link

regression: build fails with SK 2.0 and svelte-highlight >=7.4.3 #315

Closed wbhob closed 8 months ago

wbhob commented 8 months ago

When attempting to build my app using SvelteKit 2.0 and Vite 5.0, the following error occurs. The last version that builds successfully is 7.4.2.

[commonjs--resolver] Missing "./styles" specifier in "svelte-highlight" package
error during build:
Error: Missing "./styles" specifier in "svelte-highlight" package
    at e (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:25)
    at n (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:627)
    at o (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:1297)
    at resolveExportsOrImports (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29473:20)
    at resolveDeepImport (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29492:31)
    at tryNodeResolve (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29217:20)
    at Object.resolveId (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28985:28)
    at Object.handler (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/vite@5.0.10/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67017:19)
    at file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/rollup@4.9.1/node_modules/rollup/dist/es/shared/node-entry.js:18639:40
    at async PluginDriver.hookFirstAndGetPlugin (file:///Users/wilson/GitHub/Lobby/ai-www-svelte/node_modules/.pnpm/rollup@4.9.1/node_modules/rollup/dist/es/shared/node-entry.js:18539:28)
 ELIFECYCLE  Command failed with exit code 1.

CleanShot 2024-01-04 at 09 38 37@2x

metonym commented 8 months ago

Can you ensure this is the latest patch version v7.4.7?

metonym commented 8 months ago

The sveltekit example works for me – both dev and building using the node adapter. It's using SvelteKit v2.

wbhob commented 8 months ago

it appears that at one point, 'svelte-highlight/styles' was a valid import, but now it is not, so that was a major breaking change labeled as a patch release. I've updated the code to import the specific stylesheet and it's now working

metonym commented 8 months ago

I'll take a look.

metonym commented 8 months ago

@wbhob Thank you for flagging this.

Technically, it wasn't a breaking change as the barrel export files still exist (e.g., svelte-highlight/styles/index.js). The bug was that the exports map did not account for these entry points.

I published a fix in v7.4.8, which supports additional import methods:

// Base import for styles/languages
import { _default } from "svelte-highlight/styles";
import { _1c } from "svelte-highlight/languages";

// Explicit index
import { _default } from "svelte-highlight/styles/index";
import { typescript } from "svelte-highlight/languages/index";

// Explicit extension
import lang from "svelte-highlight/languages/1c.js"
import style from "svelte-highlight/styles/3024.js";

No TS errors in my IDE; Vite was able to resolve these imports in vite dev and vite build.

Screenshot 2024-01-04 at 9 19 18 PM