getHighlighter throwing error in react project
See original GitHub issuePardon my ignorance but I am new here and may not know how to properly post a question.
I am trying to install and use shiki in my react project. I have installed shiki using yarn and am trying to use getHighlighter
to highlight my code. But I am facing this weird error
Also facing below error:
Here is my code:
import React from 'react';
const shiki = require('shiki');
componentDidMount () {
shiki.getHighlighter({
theme: 'nord'
}).then((highlighter) => {
console.log(highlighter.codeToHtml("console.log('shiki');", "js"));
}).catch((e) => {
console.log(e);
});
}
Shiki version: 0.9.12
React version: 16.14.0
Please help me understand this issue and help me resolve this. What am I missing here?
Steps I followed to install and use shiki:
- yarn add shiki
- Import the module using
require('shiki')
as mentioned above - Use the imported module directly in the file where it is imported
Thanks.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Can't load in React Component · Issue #224 · shikijs/shiki
Hi, I'm trying to use Shiki in react component. But it throws an error magic header not detected import React from "react"; import...
Read more >Error Handling in React 16 – React Blog
Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them. A class component ...
Read more >How to Handle Errors in React - AppSignal Blog
Let's look at the various ways you can handle React errors. ... It is a great tool to catch misbehaving code and ensure...
Read more >How to Handle Errors Efficiently in React - X-Team
catch statement, it's hard to know where the error came from, which line of code made the app break, or which files were...
Read more >React Error Handling and Logging Best Practices
However, if any code segment throws an error, you must handle it ... only a few understand how to log errors in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In React, you have to insert the HTML markup via
dangerouslySetInnerHTML
.Here’s a React component sample:
I’m also looking to try to render server side, but it’s not working with NextJS. Do you have any idea how to fix the above error @pomber?