3

After installing @types/styled-components package and compiling my Typescript React app I keep getting error:

Module not found: Can't resolve 'styled-components'

I have dependancy in both package.json and package-lock.json and my import looks like this:

import styled from 'styled-components';

I even have the auto-completion when importing and yet after compiling, aforementioned error keeps popping up. What may be causing the problem and how to fix it?

1 Answer 1

9

You just installed the types for the library, not the library itself. That explains the autocompletion as that comes from the type declaration files (.d.ts). You should run npm i styled-components as well.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, you’re right. I thought that @types contains whole library plus types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.