I'm just trying to read a file using fs.readFileSync
, though it seems it cannot be found.
I made sure to declare it, added it within my constructor:
export default class Login extends React.Component<LoginProps, {}> {
private webAuth: auth0.WebAuth;
fs: any;
constructor(props: any, context: any) {
super(props, context);
this.fs = require('fs');
this.webAuth = new auth0.WebAuth({
clientID: conf.auth0.clientId,
domain: conf.auth0.domain,
responseType: 'token id_token',
redirectUri: `${window.location.origin}/login`
});
}
[...]
And used it in a simple function:
verifyToken = (token) => {
console.log(this.fs);
let contents = this.fs.readFileSync('../utils/public.key', 'utf8');
console.log(contents);
}
But this raises an Uncaught TypeError: _this.fs.readFileSync is not a function
. Is there a special way to include fs
in Typescript ?
Login
component is a browser component, right? Why are you trying to use thefs
module?raw-loader
.