Hello i\'m facing this issue here: Typescript Node.js simplest setup doesn't work -- error TS2307: Cannot find module 'fs'
And i\'ve tried also that sol
I know i'm probably late but i was faceing the same issue. Finally I got a work around if you want to try. In your tsconfig.json add "node_modules/@types/node" in "typeRoots" as you can see in the config bellow:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types",
"node_modules/@types/node"
],
"lib": [
"es2018",
"dom"
]
}
}
Are you running this in Node?
Why not
import fs from fs
?
Also try require
and see what's up
I found the solution:
import { writeFileSync, readFileSync } from 'fs';
it works now
This solved the issue for me:
npm install @types/node