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

Build breaks when used in a React component #4

Open
rafiwardak2003 opened this issue Sep 24, 2024 · 4 comments
Open

Build breaks when used in a React component #4

rafiwardak2003 opened this issue Sep 24, 2024 · 4 comments

Comments

@rafiwardak2003
Copy link

I am using this in a React component in Astro, and it renders the diagram and everything works fine locally. But when building for production, vitejs throws the following error:

#17 64.89 18:39:42 [ERROR] [vite] x Build failed in 8.36s
#17 65.05 node_modules/@beoe/rehype-code-hook/dist/index.js (6:9): "serialize" is not exported by "__vite-browser-external", imported by "node_modules/@beoe/rehype-code-hook/dist/index.js".
#17 65.05 file: /build/node_modules/@beoe/rehype-code-hook/dist/index.js:6:9
#17 65.05 
#17 65.05 4: // Other options: askorama/seqproto, pouya-eghbali/sia, deterministic-object-hash
#17 65.05 5: // I haven't benchmarked it
#17 65.05 6: import { serialize } from "node:v8";
#17 65.05             ^
#17 65.05 7: export { waitFor } from "./waitFor.js";
#17 65.05 8: function isNode(node) {
#17 65.05 
#17 65.05   Stack trace:
#17 65.05     at getRollupError (file:///build/node_modules/rollup/dist/es/shared/parseAst.js:392:41)
#17 65.05     at Module.error (file:///build/node_modules/rollup/dist/es/shared/node-entry.js:14844:16)
#17 65.05     at ModuleScope.findVariable (file:///build/node_modules/rollup/dist/es/shared/node-entry.js:13192:39)
#17 65.05     at FunctionBodyScope.findVariable (file:///build/node_modules/rollup/dist/es/shared/node-entry.js:5221:38)
#17 65.05     at FunctionBodyScope.findVariable (file:///build/node_modules/rollup/dist/es/shared/node-entry.js:5221:38)
@stereobooster
Copy link
Owner

I have one project which uses React + Astro:

import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import react from "@astrojs/react";
import robotsTxt from "astro-robots-txt";
import { rehypeGraphviz } from "@beoe/rehype-graphviz";

// https://astro.build/config
export default defineConfig({
  site: "",
  defaultLocale: "en",
  redirects: {},
  integrations: [
    starlight({}),
    react(),
    robotsTxt(),
  ],
  markdown: {
    remarkPlugins: [
      remarkMath,
      
    ],
    rehypePlugins: [rehypeKatex, [rehypeGraphviz, { class: "timeline" }]],
  },
});

In my case it works without issues. Can you provide reproducible example?

@rafiwardak2003
Copy link
Author

rafiwardak2003 commented Sep 24, 2024

I forgot to mention I am using it with RemarkJS since it's a React component. It's dynamic markdown coming from the server.

So something similar to this works until you add the mermaid plugin, then it won't compile:


import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'

const file = await unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeSanitize)
  .use(rehypeStringify)
  .process('# Hello, Neptune!')

console.log(String(file))

@stereobooster
Copy link
Owner

You mean you use remark on the client-side? Those plugins won't work on the client - they were built for the server.

rehype-mermaid probably will work.

I don't have a need for this functionality. PRs are welcome though

@rafiwardak2003
Copy link
Author

Okay, I will take a look at the other plugin or see if I can create a PR for this.

And yes, the component is rendered in the client side. The other remark plugins worked, just not this one. Thanks for the help.

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

2 participants