vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.26k stars 6.05k forks source link

react-markdown and vite causes site to crash only in production #3592

Closed sokryptk closed 3 years ago

sokryptk commented 3 years ago

Describe the bug

While trying to use react-markdown in my vite react starter template, the website crashes in production build with some vague error, the dev build of the same works fine.

Reproduction

https://github.com/krypticallusion/test/tree/vite/react-markdown for reproducing this error

Before submitting the issue, please make sure you do the following

I've already opened an issue on react-markdown in regards to this, as I originally thought this was a react-markdown thing. However... https://github.com/remarkjs/react-markdown/issues/598#issuecomment-850987858 considers this a vite thing.

yuyichen commented 3 years ago

我有类似的问题,我使用的是@uiw/react-md-editor,我在他们的github上提了issue

sokryptk commented 3 years ago

我有类似的问题,我使用的是@uiw/react-md-editor,我在他们的github上提了issue

Yeah! I'm using markdown-to-jsx for the meantime, Works well!

lnkusuin commented 3 years ago

I also have the same problem.

cquiroz commented 3 years ago

I’m seeing the same issue, it started with vite 2.3.0, maybe the update of esbuild?

subblue commented 3 years ago

Same here, I've dropped back to v2.2.4 for the moment. v2.3.0 introduced some breaking changes but I didn't have any luck with the suggested workaround of using the dynamic-import-polyfill - has anyone else had better luck?

ludwigHoon commented 3 years ago

I am facing the same issue in v2.4.2, curiously, it work in dev, no problem during build too. Wonder what's the difference between dev and build that cause this.

sokryptk commented 3 years ago

Hi, an update on this issue. Since this issue arises from mdast-util-to-hast. The maintainer of said library pointed that this was a vite issue and directed me here, but since then the maintainer has fixed the circular dependency issue the lib has.

Check it out here - https://github.com/syntax-tree/mdast-util-to-hast/commit/58a75f4cd7088b7d669201e7cd37bb56e5a6bf0b

Maybe this issue should now be closed?

Cheers!

Most probably, we'll have to wait for the dependent libraries to upgrade to 11.1.1.

ludwigHoon commented 3 years ago

@krypticallusion Thanks for pointing that out! I just managed to patch my local library. Spent the better half of my day figuring out what's wrong. 😅

ludwigHoon commented 3 years ago

Leaving how I patched that here in case anyone stumble across the same problem and just wanted to fix this head on.

  1. Add "postinstall": "patch-package" to package.json
  2. Copy mdast-util-to-hast+10.2.0.patch and put it in a /patches
  3. Run npx patch-package mdast-util-to-hast
  4. Run npm install

Voilà, it should work when you build. p.s. delete node_modules/.vite if dev server doesn't work.

sokryptk commented 3 years ago

Closing the issue with respect to @ludwigHoon's patch above and the dependency issue being fixed in the faulty package.