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 read properties of undefined (reading 'trim') #102

Open
Billy-Sheppard opened this issue Jun 4, 2024 · 1 comment
Open

Comments

@Billy-Sheppard
Copy link

Describe the bug
JS console error from highlightjs-line-numbers.min.js.

To Reproduce
Steps to reproduce the behavior:

...
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/vs2015.min.css" integrity="sha512-mtXspRdOWHCYp+f4c7CkWGYPPRAhq9X+xCvJMUBVAb6pqA4U8pxhT3RWT3LP3bKbiolYL2CkL1bSKZZO4eeTew==" crossorigin="anonymous" referrerpolicy="no-referrer">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js" integrity="sha512-axd5V66bnXpNVQzm1c7u1M614TVRXXtouyWCE+eMYl8ALK8ePJEs96Xtx7VVrPBc0UraCn63U1+ARFI3ofW+aA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
...

Have this in your HTML, use highlightjs (and line-numbers). Prints this to console.

highlightjs-line-numbers.min.js:1  
Uncaught TypeError: Cannot read properties of undefined (reading 'trim')
    at highlightjs-line-numbers.min.js:1:1620
    at f (highlightjs-line-numbers.min.js:1:1932)
    at highlightjs-line-numbers.min.js:1:1004

Expected behavior
No errors.

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser [e.g. chrome, safari]: Edge
  • Version [e.g. 22]: 125.0.2535.79
@angelikatyborska
Copy link

I am also experiencing this error. To add some details, for me it happens for elements whose text content is empty. E.g.

<pre><code></code></pre>
const codeElement = document.querySelectorAll("pre code")
window.hljs.highlightElement(codeElement);
(window.hljs as HLJSApi & HLJSNumbers).lineNumbersBlock(codeElement, { singleLine: true });

The raising code is this line, it raises when lines is equal to []:
https://github.com/wcoder/highlightjs-line-numbers.js/blob/master/src/highlightjs-line-numbers.js#L213

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