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

TypeError: Cannot destructure 'undefined' as it is undefined. #4206

Open
jihea-park opened this issue Feb 3, 2025 · 0 comments
Open

TypeError: Cannot destructure 'undefined' as it is undefined. #4206

jihea-park opened this issue Feb 3, 2025 · 0 comments
Labels
bug help welcome Could use help from community parser

Comments

@jihea-park
Copy link

jihea-park commented Feb 3, 2025

Describe the issue/behavior that seems buggy
I use "highlight.js": "^11.9.0",

I got this error.

TypeError: Cannot destructure 'undefined' as it is undefined.
    at Ft (index-08cefa63.js:225:186736)
    at lr (index-08cefa63.js:225:189346)
    at compileLanguage (index-08cefa63.js:225:189853)
    at Ln (index-08cefa63.js:226:3940)
    at Object.jn [as highlight] (index-08cefa63.js:226:179)
    at index-08cefa63.js:961:38248
    at Qj (index-08cefa63.js:40:27205)
    at Hk$1 (index-08cefa63.js:40:47522)
    at Ek (index-08cefa63.js:40:40990)
    at jg$1 (index-08cefa63.js:38:3736)

This is my code

import 'highlight.js/styles/atom-one-light.min.css';
import React from 'react';
import hljs from 'highlight.js/lib/core';
import typescript from 'highlight.js/lib/languages/typescript';
import sql from 'highlight.js/lib/languages/sql';
import java from 'highlight.js/lib/languages/java';
import plaintext from 'highlight.js/lib/languages/plaintext';
import { cn } from '../../lib';

hljs.registerLanguage('typescript', typescript);
hljs.registerLanguage('sql', sql);
hljs.registerLanguage('java', java);
hljs.registerLanguage('plaintext', plaintext);

export interface HighLightCodeProps {
  language?: 'typescript' | 'sql' | 'java' | 'plaintext';
  code?: string;
  className?: string;
}

export const HighLightCode = ({
  language = 'plaintext',
  code = '',
  className,
}: HighLightCodeProps) => {
  const [highLightedCode, setHighLightedCode] = React.useState(code || '');

  React.useEffect(() => {
      const result = hljs.highlight(code || '', { language, ignoreIllegals: true });
      setHighLightedCode(result.value);
    } catch (error) {
      console.error(`Highlight.js Error:`, error);
      setHighLightedCode(code || '');
    }
  }, [code, language]);

  return (
    <div className={cn('hljs', className)}>
      {highLightedCode.split('\n').map((str, i) => (
        <React.Fragment key={i}>
          <code dangerouslySetInnerHTML={{ __html: str }} className="break-all"></code>
          <br />
        </React.Fragment>
      ))}
    </div>
  );
};

Use like this,

<HighLightCode
              code={detail}
              language={'java'}
              className="h-full p-2 overflow-auto text-xs"
            />

It works fine in the local environment.
But when I deploy to production, the error occurs.
I don't know why... Please help me.

It also occurs when I use react-highlight, react-syntax-highlighter.
What should I do?

Sample Code or Instructions to Reproduce

Expected behavior

Additional context

@jihea-park jihea-park added bug help welcome Could use help from community parser labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community parser
Projects
None yet
Development

No branches or pull requests

1 participant