최대 1 분 소요

안녕하세요. Nerd Lee 입니다.

이번 글은 typescript용 styled-components를 설치할 때

Cannot find module ‘styled-components’ or its corresponding type declarations.

오류를 해결하는 방법에 대해서 알아보도록 하겠습니다.


- Cannot find module ‘styled-components’
or its corresponding type declarations. -

1. package.json 수정

react.js 환경에 있는 package.json 파일 수정

  • dependencies 또는 dev 환경으로 설치하셨다면
    devDependencies에 있는 버전을 수정해주셔야 합니다.
"dependencies": {
    ...,
    styled-components: "version",
    @types/styled-components: "version"
  },
  • 에러가 나는 이유는 두 버전의 값이 같지 않기 때문입니다.
    저 두 패키지 중, 낮은 패키지의 버전에 맞춰서 값을 변경해주시면 됩니다.

2. node_module 폴더 삭제

  • node_module 폴더를 삭제해주세요.

  • 그리고 vs code terminal 환경에서 npm i를 입력합니다.

$ npm i
  • 그럼 package.json에 있는 dependencies에 있는 패키지들을 전부 설치하게 됩니다.
    에러가 없어지고 웹페이지가 정상적으로 작동이 될 것이라고 생각이 됩니다.

이 글이 도움이 되셨다면 댓글 부탁드립니다^^
다음 글로 찾아오겠습니다!