text2svg icon indicating copy to clipboard operation
text2svg copied to clipboard

require('fs') dependency is not getting resolved with webpack build

Open s1728k opened this issue 7 years ago • 6 comments

hi

I tried to npm install with webpack and after making webpack.config.js if i run webpack command i get error for not resolving the dependency require('fs') in /node_modules/text2svg/index.js

could someone please resolve this for me

s1728k avatar Dec 14 '17 11:12 s1728k

@s1728k This module is work with nodejs.

bubkoo avatar Dec 15 '17 02:12 bubkoo

I have installed node js and using node js only please elaborate on your solution

s1728k avatar Dec 16 '17 05:12 s1728k

fs is a module in nodejs, so text2svg should be used in server-side

bubkoo avatar Dec 18 '17 05:12 bubkoo

i understand that.

while developing web apps we run web app in localhost which is an imitation of server side.

s1728k avatar Dec 18 '17 09:12 s1728k

While the index.js has a require('fs') the problem with browserify and other methods isn't specific to the text2svg package per se but it's reliance on opentype.js and most specifically it's use of readFileSync() which won't work in a browser. Presumably, to 'fix' it to work in a browser would require some kind of workaround in opentype.js to use something like fetch or axios to retrieve the font file(s). Maybe an override?

scottw-finao avatar Sep 10 '24 14:09 scottw-finao

I discovered that it's not opentype itself but how this package is calling it. I also discovered you don't need this package to convert type to svg, just use opentype.js. It already has a browser ready version with a cdn and one of the three load methods supports uris.

scottw-finao avatar Sep 17 '24 16:09 scottw-finao