Tomasz Tomasz - 1 month ago 28x
React JSX Question

ReactJS + typescript - could not import react-autosuggest

I have problem with writing in TypeScript & ReactJS. I have no idea how to import external libraries and use them properly in the code.

I'm trying to use

in my project so I'm:

  1. Installing
    npm install --save react-autosuggest

  2. Installing typing for this library with
    typings install --global --save dt~react-autosuggest

  3. going to file where I want to use this and trying to import that and use

Here I have problem, because I still have problems with importing it.

When I'm trying to import it with
import * as autosuggest from 'react-autosuggest'
I'm getting error

error TS2497: Module ''react-autosuggest'' resolves to a non-module entity and cannot be imported using this construct.

When I'm importing with
import Autosuggest from 'react-autosuggest'
another error appears:

error TS1192: Module ''react-autosuggest'' has no default export.

Could you guide me how to do it?


To fix your import use require:

import AutoSuggest = require("react-autosuggest");
new AutoSuggest();

The export of the module is done with the export = syntax. Refer to this SO for details on why you need to import this with require: