foliojs / fontkit

An advanced font engine for Node and the browser
1.46k stars 219 forks source link

readFileSync is not a function #234

Closed nmassi closed 4 years ago

nmassi commented 4 years ago

I am using react, just imported the fontkit module and I got this error:

TypeError: __webpack_require__(...).readFileSync is not a function
(anonymous function)
src/opentype/shapers/ArabicShaper.js:5

src/opentype/sharpers/ArabicSharper.js

const trie = new UnicodeTrie(require('fs').readFileSync(__dirname + '/data.trie'));

Does anyone know if it there a workaround to fix webpack when using create-react-app?

nmassi commented 4 years ago

Using import fk from 'fontkit/base' instead of 'fontkit' seems to solve the problem. Does anyone knows why is this?