Brick Brick - 5 months ago 104
Javascript Question

How to find module "fs" in MS Code with TypeScript?

I'm running on a MacBook Air. I installed MS Code as an IDE and also have TypeScript installed.

I have a simple file with just this line:

import fs = require('fs');

I'm getting a red squiggly under the 'fs' inside the parenthesis and the error message is
[ts] Cannot find module 'fs'.
The file has a .ts extension. I'm new to JavaScript and to TypeScript, but I was under the impression that
was a core module, so how could it not be found? How do I fix the problem?

Other things that I tried already:

  • Putting a simple function body in the file and then compiling on the command line with
    . I get an essentially equivalent error there:
    error TS2307: Cannot find module 'fs'.

  • On the command line
    sudo npm install fs -g
    . This reports apparent success, but doesn't fix the problem.

I poked around SE and the web, but the answers that seemed close all appear to assume that 'fs' is available.


You need to include the definition file for node (found here).

If you use typings then you can run this command:

typings install dt~node --global --save