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!
To solve the "Cannot find module fs or its corresponding type declarations" error, install the types for node by running the command npm i -D @types/node . You can then import fs with the following line of code import * as fs from 'fs' .
tsc throws `TS2307: Cannot find module` for a local file.
To import and use the fs module in TypeScript, make sure to install the type definitions for node by running npm i -D @types/node and import fs with the following line import * as fs from 'fs' , or import { promises as fsPromises } from 'fs' if using fs promises.
To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the baseUrl option to src in your tsconfig. json file and restart your IDE and development server.
You should install @types
locally to your project.
npm install @types/node --save-dev
TypeScript will not find globally installed types as definition files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With