Typescript Node.js the simplest setup does not work - error TS2307: cannot find module 'fs'

I set the TS and node tables globally:

PS C:\Projects\Test> npm list --global --depth=0
C:\Users\Jan\AppData\Roaming\npm
+-- @types/node@7.0.5
+-- tslint@4.4.2
`-- typescript@2.2.1

Then I created the test.ts file

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

Running tsc results in

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

Skip something obvious?

Thank!

+4
source share
1 answer

You must install @typeslocally in your project.

npm install @types/node --save-dev

TypeScript will not display globally defined types as definition files.

+4
source

Source: https://habr.com/ru/post/1670714/


All Articles