nipun-kavishka
nipun-kavishka

Reputation: 922

Cannot find name 'require' - Angular 8

Cannot compile after using fast-image-size node module. I tried serveral steps to slove this but nothis helped. Finally I add "types": ["ts-node"], to tsconfig.js file , but not helped. How do I solve this?? My typescript version is 3.7.3 .

How this error display

Upvotes: 3

Views: 7453

Answers (2)

Sadaf Niknam
Sadaf Niknam

Reputation: 559

You can declare var require: any

Also instead of var fast_image_size = require('../index.js') you could try the following:

import fast_image_size from '../index.js' // or
import fast_image_size = require('../index.js')

Upvotes: 5

cmprogram
cmprogram

Reputation: 1884

You're receiving this error because this is not how TypeScript handles file imports. TypeScript handles importing or including files in a slightly different manner. To resolve this:

-Remove line 198 ("var fast_image_size = require("..index.js");")

-Instead, at the top of the file add the following line:

import * as fast_image_size from '..index.js'

The rest of your script should then compile.

Upvotes: 1

Related Questions