Importing nodejs `fs` with typescript when executing with ts-node?
Asked Answered
P

1

31

I'm trying to run the following code with ts-node.

import { writeFileSync, readFileSync } from 'fs';

However I get:

src/main/ts/create.ts (1,45): Cannot find module 'fs'. (2307)

What do I need to do in to allow typescript to import the fs module?

Piatt answered 6/5, 2017 at 21:12 Comment(0)
K
50

You need to run:

$ npm install @types/node --save-dev

If you need additional information you can refer to the NodeJS QuickStart in the TypeScript Deep Dive by Basarat.

Kronfeld answered 6/5, 2017 at 23:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.