shiki icon indicating copy to clipboard operation
shiki copied to clipboard

Can't load in React Component

Open gigara opened this issue 3 years ago • 2 comments

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;

Screenshot from 2021-09-08 10-51-10

What is the correct way to use Shiki in a react class component?

gigara avatar Sep 08 '21 05:09 gigara

Does javascript/auto work?

https://github.com/pine/arraybuffer-loader/issues/12#issuecomment-390834140 https://github.com/webpack/webpack/issues/7264#issuecomment-388377363

octref avatar Sep 18 '21 05:09 octref

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.

lithdew avatar Oct 03 '21 18:10 lithdew