Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Cannot find Module "fs" even though @types/node installed

I know the usual fix for this one is to install @types/node , and I have 10.12.23 of that installed.

This appears to be a strange error and I am a bit baffled by it. I have 2 other npm modules installed: config ( which requires @types/config ) and firebase-admin which must have it's own typescript types. Also using VS code version 1.31 . I even tried installing an older version of @types/node

The following works fine

import admin from "firebase-admin";
import fs from "fs";

The following fails: cannot find module 'fs'

import admin from "config";
import fs from "fs";

The following fails: cannot find module 'fs'

import fs from "fs";

I am not using any other packages / webpack or anything else. Any ideas are appreciated.

like image 710
Martin Thompson Avatar asked Feb 08 '19 21:02

Martin Thompson


1 Answers

Besides installing @types/node, check that the tsconfig.json:

  • does not have a compilerOptions types, or make sure "node" is included there
  • noResolve does not exist or is set to false
  • esModuleInterop is set to true or you'll get error Module "fs" has no default export
like image 137
drodsou Avatar answered Oct 31 '22 00:10

drodsou