kklw
kklw

Reputation: 888

Typescript unable to import fileReader

How do i import FileReader in typescript. I tried this:

var reader:FileReader = new FileReader();

my tsconfig.json

{
"compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "out",
    "lib": [
        "es6"
    ],
    "sourceMap": true,
    "rootDir": "."
},
"exclude": [
    "node_modules",
    ".vscode-test"
]
}

My error is cannot find name 'FileReader' I am unable to do this too:

import FileReader;

Upvotes: 2

Views: 6000

Answers (1)

Sigex
Sigex

Reputation: 2949

I ran into this issue as I forgot to add "dom" to the "lib" node in the tsconfig.json.

Fix:

In your tsconfig.json ensure under "lib" you have "dom". Here is my current tsconfig.json

{
   "compilerOptions": {
      "lib": [
         "dom",
         "dom.iterable",
         "esnext",
         "es5",
         "es6"
      ],
      "target": "es5",
      "module": "commonjs",
      "moduleResolution": "node",
      "outDir": "./build",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "sourceMap": true
   }
}

See the below ugly themed VS code the lib.dom.d.ts is where the FileReader interface lives which made me realise I was missing "dom"

enter image description here

Upvotes: 4

Related Questions