#Error with FS in TS

1 messages · Page 1 of 1 (latest)

fervent stag
#

Heyy! i have a problem while using fs in typescript file... Thats return me this error !

font.tsx:11 Uncaught TypeError: (0 , fs__WEBPACK_IMPORTED_MODULE_2__.readdirSync) is not a function
    at ./src/Tools/font.tsx (font.tsx:11:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./App.tsx (bundle.js:24:77)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./node_modules/expo/AppEntry.js (styleToBarStyle.web.ts:19:1)
    at __webpack_require__ (bootstrap:24:1)
    at startup:6:1
    at startup:6:1

Code part:

import {readdirSync} from 'fs';
import React from "react";

import { useFonts } from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';

const fontDir = '../../assets/fonts/';

const fonts = readdirSync(fontDir);
dusky berry
#

that's not a problem of ts

fervent stag
dusky berry
#

fs isn't available on the front end

fervent stag
#

not cool 😦

#

thx for the info !

dusky berry
#

i don't think they exist on the front end unless you just expose them publically or something like that

#

im not sure about the details there tbh

civic monolith
#

there are shims for webpack

#

but they won't do a thing obviously

fervent stag
#

so im gonna add all of my font manually 😦

civic monolith
#

you can bundle them with you app

#

using import statements

#

think it is supported in webpack

glacial sandal
#

yeah i think this is less a typescript issue and more a webpack issue

#

i'm not sure ditching typescript will make this work

#

i think the normal way to go is to manually import every file

#

because there are plugins for that

fervent stag
glacial sandal
fervent stag
#

so, thanks all for the information im gonna close this thread 🙂