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

Can ReactMarkdown be used with react-lazy-load? #852

Closed
4 tasks done
hobin2017 opened this issue Aug 14, 2024 · 2 comments
Closed
4 tasks done

Can ReactMarkdown be used with react-lazy-load? #852

hobin2017 opened this issue Aug 14, 2024 · 2 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@hobin2017
Copy link

hobin2017 commented Aug 14, 2024

Initial checklist

Affected packages and versions

"react-markdown": "^9.0.1"

Link to runnable example

No response

Steps to reproduce

package.json

{
  "dependencies": {
    "react-markdown": "^9.0.1",
    "antd": "^4.24.0",
    "less": "^4.1.3",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.4.3"
  },
  "devDependencies": {
    "@types/react": "^18.0.22",
    "@types/react-dom": "^18.0.7",
    "@vitejs/plugin-react": "^2.2.0",
    "typescript": "^4.6.4",
    "vite": "^3.2.0"
  }
}

react

the ReactMarkdown component is wrapped in a new class. and this class is imported by React.lazy method.
src/render_md.tsx

import * as React from 'react'
import ReactMarkdown from 'react-markdown'

export class RenderMarkdown extends React.Component<{}, {}> {
  render() {
    return (
      <div
        style={{
          height: 300,
          overflowY: 'scroll',
        }}
      >
        <ReactMarkdown>
          {"# title"}
        </ReactMarkdown>
      </div>
    )
  }
}

export default RenderMarkdown

App.tsx

import * as React from 'react'

function App() {
  const DynamicComponent = React.lazy(() => import("@/render_md"))
  return (
      <React.Suspense fallback={<div>loading component</div>}>
        <DynamicComponent />
      </React.Suspense>
  )
}

export default App

Expected behavior

no extra config in vite.config.ts

Actual behavior

[vite]: Rollup failed to resolve import "#minpath" from "node_modules/vfile/lib/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

After adding external: ['vfile'] in vite.config.ts, the yarn-build problem is gone but another error appears in the chrome:

Uncaught TypeError: Failed to resolve module specifier "vfile". Relative references must start with either "/", "./", or "../".

Runtime

Node v16

Package manager

yarn 1

OS

Linux

Build and bundle tools

Vite

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Aug 14, 2024
@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
@wooorm wooorm added the 🙋 no/question This does not need any changes label Aug 14, 2024

This comment has been minimized.

@wooorm
Copy link
Member

wooorm commented Aug 14, 2024

This is also a duplicate of https://github.com/orgs/remarkjs/discussions/1356

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants