hexenq / kuroshiro

Japanese language library for converting Japanese sentence to Hiragana, Katakana or Romaji with furigana and okurigana modes supported.
https://kuroshiro.org
MIT License
837 stars 94 forks source link

KuromojiAnalyzer is not a constructor #109

Open ChesterAiGo opened 1 year ago

ChesterAiGo commented 1 year ago

I know everyone's getting Kuroshiro is not a constructor and resolves the problem with adding a default

But i don't see anyone getting this weird error as mine:

KuromojiAnalyzer is not a constructor
TypeError: KuromojiAnalyzer is not a constructor

My code is:

const Kuroshiro = require("kuroshiro").default;
const KuromojiAnalyzer = require("kuroshiro-analyzer-kuromoji");

function someComponent({ text }) {

  const kuroshiro = new Kuroshiro();
  const analyzer = new KuromojiAnalyzer();

  // Convert the Japanese text to Romaji
  let captionedText;
  kuroshiro.init(analyzer)
    .then(function(){
      captionedText = kuroshiro.convert(text, { to: "romaji" });
    })
    .then(function(captionedText){
        console.log(captionedText);
    })

and it fails with the error above Any hint or help would be immensely appreciated! :)