Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  127] [ 1]  / answers: 1 / hits: 124145  / 8 Years ago, mon, may 16, 2016, 12:00:00

I'm running on a MacBook Air. I installed VS 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 fs 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 tsc. 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.


More From » typescript

 Answers
2

You need to include the definition file for node.



TypeScript 2.0+



Install using npm:



npm install --save-dev @types/node


TypeScript < 2.0



If you use typings then you can run this command:



typings install dt~node --global --save


Or if you are using typings < 1.0 run:



typings install node --ambient --save


Or if all else fails, manually download the file here and include it in your project.


[#62147] Saturday, May 14, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;