Open shivarajnaidu opened 1 year ago
Same error :(
same error
Same error. Can we have another way to hightlight code block
I ended up migrating to https://github.com/mapbox/rehype-prism and my setup now looks like this:
import rehypePrism from "@mapbox/rehype-prism";
import rehypeStringify from "rehype-stringify";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import { unified } from "unified";
export async function getContentFromMarkdown(page: string): Promise<string> {
const content = await unified()
.use(remarkParse) // Parse markdown content to a syntax tree
.use(remarkRehype) // Turn markdown syntax tree to HTML syntax tree, ignoring embedded HTML
.use(rehypePrism as any)
.use(rehypeStringify) // Serialize HTML syntax tree
.process(page);
return content.toString();
}
Same error :(
Same, @sergioramos
same error
+1
+1 Next.js (14.2.4) with typescript
code sniped
async function markdownToHtml(markdown: string) {
const file = await unified()
.use(remarkParse) // Parse Markdown to a syntax tree
.use(remarkPrism as any) // Add syntax highlighting to code blocks
.use(remarkRehype) // Transform Markdown syntax tree to HTML syntax tree
.use(rehypeStringify) // Serialize HTML syntax tree to HTML
.process(markdown)
return String(file)
}
removing .use(remarkPrism as any)
works
Unhandled Runtime Error
Error: ENOENT: no such file or directory, open '(rsc)/./node_modules/prismjs/prism.js'
Source
readFileSync
node:fs (448:20)
module.exports
node_modules/remark-prism/src/highlight.js (142:1)
eval
node_modules/remark-prism/src/index.js (74:1)
wrapped
node_modules/trough/lib/index.js (160:1)
next
node_modules/trough/lib/index.js (86:1)
Object.run
node_modules/trough/lib/index.js (57:1)
executor
node_modules/unified/lib/index.js (901:1)
Function.run
node_modules/unified/lib/index.js (884:1)
executor
node_modules/unified/lib/index.js (737:1)
new Promise
<anonymous>
Function.process
node_modules/unified/lib/index.js (720:1)
src/app/blog/[slug]/page.tsx (23:6) @ process
21 | .use(remarkRehype) // Transform Markdown syntax tree to HTML syntax tree
22 | .use(rehypeStringify) // Serialize HTML syntax tree to HTML
> 23 | .process(markdown)
| ^
24 | return String(file)
25 | }
26 |
Call Stack
markdownToHtml
src/app/blog/[slug]/page.tsx (50:29)
getPostData
src/app/blog/[slug]/page.tsx (70:22)
Next.js
Hide collapsed frames
I found a solution for the issue by adding remark-prism
to the Next.js configuration. This works for Next.js version 14+.
Here's the full configuration:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ['remark-prism']
},
}
export default nextConfig
This resolved the problem for me. I hope this helps others facing the same issue!
same error :(
+1
I have the below code in my blog but it is throwing an error saying
Error: ENOENT: no such file or directory, open '(rsc)/./node_modules/prismjs/prism.js'
I am using NextJs 13.5 and
Error