【问题标题】:Could not find a declaration file for module 'styled-components/native'找不到模块“styled-components/native”的声明文件
【发布时间】:2022-06-21 00:52:57
【问题描述】:

如果您将styled-components 添加到您的 React Native 项目中,则会有一个专门用于本地组件的子目录:

import styled from 'styled-components/native`;

export const Container = styled.View`
  ...
`;

如果您尝试在 React Native TypeScript 项目中执行此操作,您将遇到以下类型错误:

Could not find a declaration file for module 'styled-components/native'.

解决此问题的典型方法是在您的开发依赖项中安装 @types/styled-components 模块,但这并不能解决问题。

【问题讨论】:

    标签: typescript react-native styled-components


    【解决方案1】:

    https://github.com/styled-components/styled-components/issues/2099#issuecomment-749776524

    styled-components/native 类型已移至 @types/styled-components-react-native

    所以,要解决:

    npm install --save-dev @types/styled-components-react-native
    

    yard add -D @types/styled-components-react-native
    

    【讨论】:

      猜你喜欢
      • 2022-08-22
      • 2020-12-17
      • 2021-06-17
      • 2022-09-25
      • 2019-04-03
      • 1970-01-01
      • 2022-07-12
      • 2017-08-13
      • 1970-01-01
      相关资源
      最近更新 更多