Knack
Knack

Reputation: 1134

Typescript Node.js simplest setup doesn't work -- error TS2307: Cannot find module 'fs'

I've installed TS and the node typings globally:

PS C:\Projects\Test> npm list --global --depth=0
C:\Users\Jan\AppData\Roaming\npm
+-- @types/[email protected]
+-- [email protected]
`-- [email protected]

Then I've created a file test.ts

import fs = require("fs");
let text = fs.readFileSync("myFile.txt");
console.log(text);

Runnning tsc results in

PS C:\Projects\Test> tsc .\test.ts
test.ts(1,21): error TS2307: Cannot find module 'fs'.

Do I miss something obvious?

Thanks!

Upvotes: 8

Views: 5975

Answers (1)

Herrington Darkholme
Herrington Darkholme

Reputation: 6315

You should install @types locally to your project.

npm install @types/node --save-dev

TypeScript will not find globally installed types as definition files.

Upvotes: 7

Related Questions