Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

Cannot read properties of undefined (reading 'Registry') #276

@fantienan

Description

@fantienan

Describe the bug

我使用rolldown-vite@latest构建生产版本,然后pnpm preview后报错:Cannot read properties of undefined (reading 'Registry'),原因是我的代码中用到了@wooorm/starry-night@3.8.0@wooorm\starry-night\lib\index.jsimport vscodeTextmate from 'vscode-textmate',在打包后vscodeTextmate变成了undefined

Reproduction

a

Steps to reproduce

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 3.66 GB / 13.86 GB
  Binaries:
    Node: 22.15.0 - C:\software\nvm4w\nodejs\node.EXE
    Yarn: 1.22.22 - C:\software\nvm4w\nodejs\yarn.CMD
    npm: 11.4.2 - C:\software\nvm4w\nodejs\npm.CMD
    pnpm: 10.8.0 - C:\workspace\codes\@ai\ai-dashboard\node_modules\.bin\pnpm.CMD
    bun: 1.2.16 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (134.0.3124.93)
    Internet Explorer: 11.0.19041.5794
  npmPackages:
    @vitejs/plugin-react-swc: ^3.8.0 => 3.10.2
    rolldown-vite:  6.3.21

Used Package Manager

npm

Logs

很抱歉我不能提供仓库地址,下面是我的源码:

import 'github-markdown-css/github-markdown.css'
import { Copy2Clipboard } from '@/components/copy-2-clipboard'
import { cn } from '@/lib/utils'
import { common } from '@wooorm/starry-night'
import tsx from '@wooorm/starry-night/source.tsx'
import { Check } from 'lucide-react'
import { createRef, memo } from 'react'
import { MarkdownHooks } from 'react-markdown'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStarryNight from 'rehype-starry-night' 
import remarkGfm from 'remark-gfm'
import { CopyIcon } from '../icons'

const remarkPlugins = [remarkGfm]

const rehypePlugins = [
  rehypeSanitize,
  () => rehypeStarryNight({ grammars: [...common, tsx], allowMissingScopes: true }),
]

const NonMemoizedMarkdown = ({
  children,
  inline,
  className: propClassName,
}: { children: string; inline?: boolean; className?: string }) => {
  if (inline) return <pre>{children}</pre>

  return (
    <div className={cn('markdown-body', propClassName)}>
      <MarkdownHooks
        remarkPlugins={remarkPlugins}
        rehypePlugins={rehypePlugins}
        components={{
          pre: ({ children: c, node, className, ...props }) => {
            const ref = createRef<HTMLPreElement>()
            const code = node?.children[0] as any
            let language = 'text'
            if (code?.properties?.className) {
              const codeClassName = code.properties.className.find((v: string) => /language-(\w+)/.exec(v))
              const match = /language-(\w+)/.exec(codeClassName || '')
              language = match ? match[1] : 'text'
            }

            return (
              <pre
                {...props}
                ref={ref}
                className={cn(
                  className,
                  'border border-zinc-200 dark:border-zinc-700 rounded-xl p-4 my-4 overflow-x-auto',
                )}
              >
                <span className="flex justify-between items-center text-sm text-gray-500 dark:text-gray-400 mb-2">
                  {language && <span>{language}</span>}
                  <Copy2Clipboard
                    className="flex items-center gap-1 cursor-default"
                    text={() => {
                      if (!ref.current) return ''
                      return ref.current.querySelector('code')?.textContent || ''
                    }}
                  >
                    {(copied) => (
                      <>
                        {copied ? <Check size={14} /> : <CopyIcon size={14} />}
                        复制
                      </>
                    )}
                  </Copy2Clipboard>
                </span>
                {c}
              </pre>
            )
          },
        }}
      >
        {children}
      </MarkdownHooks>
    </div>
  )
}

export const Markdown = memo(NonMemoizedMarkdown, (prevProps, nextProps) => {
  if (prevProps.children !== nextProps.children) return false
  if (prevProps.className !== nextProps.className) return false
  if (prevProps.inline !== nextProps.inline) return false
  return true
})

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions