Namindu Sanchila
Namindu Sanchila

Reputation: 414

Module not found: Error: Can't resolve 'react-select' with typescript

module import is not working for me. I'm tried different solutions provided from stack overflow and other. These are steps I'm follow the react-select

npm install --save @types/react-select

import the module like this

import Select from "react-select"

but I got the error

Module not found: Error: Can't resolve 'react-select'

import * as React from "react";
import ReactSelect from 'react-select'
export class Select extends extends React.Component<someProps>{

render(){
   return(
  <Select id="color" options={options} />
);
}
}

But I can't find the way to fixed this.

Upvotes: 7

Views: 31531

Answers (5)

Lukas Helebrandt
Lukas Helebrandt

Reputation: 361

In my case, the problem was that the project I am working on uses an old version of react-select. In version 5, react-select was rewritten in typescript, and the types package (@types/react-select) became a stub package, with no actual type definitions in it.

So if you are using react-select in version <5, you have to specify the version of the types definitions package, that matches (or is close to) the version you are using. For example, if your react-select is in version 3.2.0, the definition in package.json would be:

"devDependencies": {
    "@types/react-select": "^3.1.2"
  }

For available versions of the package, visit https://www.npmjs.com/package/@types/react-select?activeTab=versions

Upvotes: 0

Izu
Izu

Reputation: 52

My error was a bit different since it involves react-select-async-paginate.

So in my case, I had to use,

npm install react-select react-select-async-paginate

or

yarn add react-select react-select-async-paginate

Hope this helps someone :)

Upvotes: 0

Ashwani Panwar
Ashwani Panwar

Reputation: 4578

I got solution by npm i react-select.

Upvotes: 11

Namindu Sanchila
Namindu Sanchila

Reputation: 414

I found the issue having here. Issue is both @types/react-select and react-select added to the package.json

Upvotes: 2

Nurbol Alpysbayev
Nurbol Alpysbayev

Reputation: 21911

You have an error:

npm install --save @type/react-select

instead of

npm install --save @types/react-select

Also I would recommend to use --save-dev instead of --save because you don't need typings in production.

Upvotes: 4

Related Questions