-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
I am encountering a build error when attempting to use harfbuzzjs within a Next.js application, specifically within a client-side component, while using next dev --turbopack. The build fails with a "Module not found: Can't resolve 'fs'" error, pointing to node_modules/harfbuzzjs/hb.js.
const hbPromise =
typeof window !== "undefined"
? import("harfbuzzjs")
: Promise.resolve({ default: {} });
let hb: any;
export async function initHarfBuzz() {
if (!hb) hb = await hbPromise;
return hb;
}
export async function shapeArabicText(
fontArrayBuffer: ArrayBuffer,
text: string,
) {
const hbInst = await initHarfBuzz();
const blob = hbInst.createBlob(fontArrayBuffer);
const face = hbInst.createFace(blob, 0);
const font = hbInst.createFont(face);
font.setScale(1000, 1000);
const buf = hbInst.createBuffer();
buf.addText(text);
buf.guessSegmentProperties();
hbInst.shape(font, buf);
const json = buf.json(); // contains glyph info + clusters + positions
buf.destroy();
font.destroy();
face.destroy();
blob.destroy();
return json;
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels