shiki
shiki copied to clipboard
Can't load in React Component
Hi,
I'm trying to use Shiki in react component. But it throws an error magic header not detected
import React from "react";
import onigasm from 'arraybuffer-loader!shiki/dist/onigasm.wasm';
class CodeBlock extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
async function renderCode() {
const shiki = await import("shiki");
shiki.setOnigasmWASM(onigasm)
const highlighter = await shiki.getHighlighter({
theme: "dark-plus"
});
console.log( highlighter.codeToHtml(
`console.log('sdsds');`,
"js"
));
}
renderCode();
}
render() {
...
}
}
export default CodeBlock;
What is the correct way to use Shiki in a react class component?
Does javascript/auto
work?
https://github.com/pine/arraybuffer-loader/issues/12#issuecomment-390834140 https://github.com/webpack/webpack/issues/7264#issuecomment-388377363
Does
javascript/auto
work?pine/arraybuffer-loader#12 (comment) webpack/webpack#7264 (comment)
Does not seem to work with create-react-app - error occurs even if javascript/auto
is specified.