First. I can not imagine a single case where you would use fs inside the React component. Although you can use React on the server for rendering, the same code should be executed on the client, but you have no way to access fs on the client.
If you want to use fs on the server , this is an example:
import * as fs from 'fs'; import * as path from 'path'; fs.readFile(path.join(__dirname, '../../client/index.html'), 'utf8', (error, data) => { // ... })
Make sure your package.json file has a node dependency
"dependencies": { "@types/node": "^7.0.5" }
And here is my tsconfig.json file:
{ "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "es5", "jsx": "react", "allowJs": true, "typeRoots": [ "./node_modules/@types" ] }, "include": [ "./db/**/*", "./src/**/*" ] }
source share