我只是想尝试使用文件fs.readFileSync,虽然它似乎无法找到.
我确保声明它,在我的构造函数中添加它:
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`
});
}
[...]
Run Code Online (Sandbox Code Playgroud)
并在一个简单的功能中使用它:
verifyToken = (token) => {
console.log(this.fs);
let contents = this.fs.readFileSync('../utils/public.key', 'utf8');
console.log(contents);
}
Run Code Online (Sandbox Code Playgroud)
但这提出了一个Uncaught TypeError: _this.fs.readFileSync is not a function.是否有一种特殊的方式包含fs在Typescript中?