Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suddenly getting Error: Cannot find module 'prismjs/components/prism-css' with SvelteKit #484

Closed
swyxio opened this issue Nov 30, 2022 · 8 comments

Comments

@swyxio
Copy link
Contributor

swyxio commented Nov 30, 2022

i moved swyxkit off of esbuild recently (due to netlify issues) and found that all my page renders with code samples were failing (https://swyxkit.netlify.app/welcome now 404's because i did clumsy error handling) due to this new error:

image

Dec 1, 12:35:14 AM: 98ea8b15 ERROR  Error: Cannot find module 'prismjs/components/prism-css'
Require stack:
- /var/task/node_modules/mdsvex/dist/main.cjs.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at load_language (/var/task/node_modules/mdsvex/dist/main.cjs.js:25714:3)
    at /var/task/node_modules/mdsvex/dist/main.cjs.js:25712:38
    at Set.forEach (<anonymous>)
    at load_language (/var/task/node_modules/mdsvex/dist/main.cjs.js:25712:20)
    at code_highlight (/var/task/node_modules/mdsvex/dist/main.cjs.js:25773:4)
    at /var/task/node_modules/mdsvex/dist/main.cjs.js:25745:25 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/var/task/node_modules/mdsvex/dist/main.cjs.js' ]
}

i dont have prismjs as a dep so actually took a bit of digging (npm ls prism-svelte) to figure out that it was mdsvex.

i dont know the direct cause yet but just filing an issue for others to find

@swyxio
Copy link
Contributor Author

swyxio commented Nov 30, 2022

Given that this only happens in prod and not in dev, i have to conclude that this is because the prismjs transitive dep doesnt get bundled for serverless rendering

another bug to file for sveltejs/kit#3535

@swyxio
Copy link
Contributor Author

swyxio commented Dec 14, 2022

i think this is the offending line

require(langs[lang].path);

@swyxio
Copy link
Contributor Author

swyxio commented Dec 14, 2022

trying to solve it by installing prism as a dependency, not transitive devdep https://app.netlify.com/sites/swyxkit/deploys/6399e77da4ac1300087a13c7

update: didnt work

@swyxio
Copy link
Contributor Author

swyxio commented Jan 3, 2023

was able to repro on a clean sveltekit install geoffrich/sveltekit-satori-mdsvex-test#1

@codercatdev
Copy link

Yes same issue on codingcat rewrite.

For now I am manually importing to at least get most pages working.

import prism from 'prismjs';
import 'prismjs/components/prism-bash.js';
import 'prismjs/components/prism-dart.js';
import 'prismjs/components/prism-diff.js';
import 'prismjs/components/prism-typescript.js';
import 'prismjs/components/prism-jsx';
import 'prism-svelte';

https://github.com/CodingCatDev/v2-codingcat.dev/blob/5c562fe4e2415cbd2c15ec8a0ada7a30d4e187fa/apps/codingcatdev/src/lib/server/content.js#L9

@swyxio
Copy link
Contributor Author

swyxio commented Jan 8, 2023

another related bug:

tried to solve this problem by swapping out the syntax highlighter:

image

but the dynamic import and error is still happening.

i suspect because even tho the highlighter is swapped out, the metadata isnt

load_language_metadata();

@stefanrows
Copy link

I have the same issue with an Astro project.

Error - Cannot find module './prism-markup-templating' Require stack: - /var/task/.netlify/functions-internal/entry.js - /var/task/entry.js - /var/runtime/index.mjs

Error: Cannot find module './prism-markup-templating'
Require stack:
- /var/task/.netlify/functions-internal/entry.js
- /var/task/entry.js
- /var/runtime/index.mjs
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at /var/task/.netlify/functions-internal/entry.js:11692:38
    at handleId (/var/task/.netlify/functions-internal/entry.js:11572:21)
    at loadComponentsInOrder (/var/task/.netlify/functions-internal/entry.js:11590:11)
    at Object.load (/var/task/.netlify/functions-internal/entry.js:11658:20)
    at loadLanguages2 (/var/task/.netlify/functions-internal/entry.js:11684:48)
    at ensureLoaded (/var/task/.netlify/functions-internal/entry.js:24461:37)
    at runHighlighterWithAstro (/var/task/.netlify/functions-internal/entry.js:24470:5)
    at AstroComponentInstance2.factory (/var/task/.netlify/functions-internal/entry.js:24488:35)

When I change my app from SSR to Static Rendering, prism works as intended, it seems.

@swyxio
Copy link
Contributor Author

swyxio commented Mar 10, 2023

i dont have a repro anymore but for future devs reading this, check out swyxkit. open your own issues with yoru own repro

@swyxio swyxio closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants