【问题标题】:Can't import typescript react-modal无法导入打字稿反应模式
【发布时间】:2017-09-12 01:06:29
【问题描述】:

我从这里的一个开源项目开始:

https://github.com/vega/voyager

让它工作了,我想添加一个模式。

所以我跑了:

yarn add react-modal
yarn add @types/react-modal

然后我添加了:

import {ReactModal} from 'react-modal';

我正在构建这个 ./src/components/header/chrono-history.tsx 中的错误 (5,9): 错误 TS2305: 模块 '"/Users/brennanwallace/psa/voyager/node_modules/@types/react-modal/index"' 没有导出成员 'ReactModal'。

并且 web-storm 同意存在问题,因为它在文本编辑视口中给出了相同的错误。

我能做什么?

我是键入脚本的新手,但文件似乎井井有条:

在 node_modules 的 @types 中有一个 react-modal 文件夹,其中 index.d.ts 与其他几个模块一样(它缺少其他包似乎具有的 types-metadata.json 文件)。

还有一个 react-modal 包。

tsconfig.json 文件也按顺序排列:https://github.com/vega/voyager/blob/vy2/tsconfig.json

【问题讨论】:

    标签: javascript reactjs typescript npm react-modal


    【解决方案1】:

    您必须将其导入为:

    import * as ReactModal from 'react-modal';
    

    【讨论】:

    • 我确实做到了这一点,但它没有帮助。仍然收到错误React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of ...
    猜你喜欢
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2021-11-11
    • 2016-05-21
    • 2016-11-01
    • 2020-11-11
    • 2018-05-12
    相关资源
    最近更新 更多