Search code examples
typescriptreact-nativestyled-components

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


If you add styled-components to your React Native project, there's a sub-directory for the native components specifically:

import styled from 'styled-components/native`;

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

If you try to do this in a React Native TypeScript project, you'll run into the following typings error:

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

The typical approach to resolving this would be to install the @types/styled-components module in your dev dependencies, however this does not resolve the issue.


Solution

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

    The styled-components/native types moved to @types/styled-components-react-native.

    So, to resolve:

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

    or

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