0

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 react-autosuggest in my project so I'm:

  1. Installing react-autosuggest with 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?

Tomasz
  • 2,051
  • 3
  • 31
  • 64

1 Answers1

2

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: https://stackoverflow.com/a/29598404/5324369

Community
  • 1
  • 1
Bjørn Sørensen
  • 901
  • 1
  • 6
  • 14