找不到模块:错误:无法使用打字稿解析“反应选择”

时间:2018-11-13 11:08:29

标签: reactjs typescript react-select

模块导入不适用于我。我尝试了堆栈溢出和其他提供的不同解决方案。 这些是我遵循的“反应选择”步骤

npm install --save @types/react-select

像这样导入模块

import Select from "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} />
);
}
}

但是我找不到解决此问题的方法。

3 个答案:

答案 0 :(得分:2)

您遇到错误:

npm install --save @type/react-select

代替

npm install --save @types/react-select

我也建议您使用--save-dev而不是--save,因为您不需要在生产环境中键入内容。

答案 1 :(得分:2)

我通过npm i react-select得到了解决方案。

答案 2 :(得分:0)

我发现这里有问题。问题是@types/react-selectreact-select都添加到了package.json