Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 우선순위 큐
- 리액트
- 지갑
- 프로그래밍
- Mnemonic
- 백준
- bip39
- 기본 수학 2단계
- three.js
- baekjoon
- C++
- Blockchain
- Storybook
- 니모닉
- SASS
- SVG
- frontend
- 풀이
- React
- 블록체인
- TypeScript
- priority queue
- 알고리즘
- algorithm
- Console
- 스토리북
- 에러
- 기본수학1단계
- scss
- 코딩
Archives
- Today
- Total
Moong
[React+Typescript] Storybook 에러 해결법 - element type is invalid 본문
storybook을 작성하다 이런 에러를 마주쳤다면 원인은 두 가지 중 하나입니다.

1. 컴포넌트 경로를 제대로 설정 하지 않은 경우
컴포넌트 경로가 잘못되진 않았는지 체크해주세요!
✅ export default로 내보내고 있는 component는 중괄호 없이 가져오고 있는지 확인할 것
=> import Component from './Component';
✅ export로 내보내고 있는 component는 중괄호를 포함하여 import 하고 있는지 확인할 것
=> import { Component } from './Component';
2. 스토리북에서 svg를 제대로 못 읽어오는 경우
아무리 봐도 컴포넌트 경로를 제대로 설정했다면, 스토리북 자체에서 svg를 제대로 읽어오지 못하는 것이 원인일 수 있습니다.
svg 못읽어오는 경우 해결방법
webpack.config.js 파일 추가하기
.storybook 폴더에
webpack.config.js 파일을 생성하고 다음과 같이 작성해줍니다.
// webpack.config.js
module.exports = async ({ config }) => {
const fileLoaderRule = config.module.rules.find(rule => rule.test.test('.svg'));
fileLoaderRule.exclude = /\.svg$/;
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack", "url-loader"],
});
return config;
};
해결 완료! 🙌

'React' 카테고리의 다른 글
| [React+Typescript] Storybook에 라우터(react-router-dom) 설정하기 (0) | 2023.05.04 |
|---|---|
| [React+Typescript] Storybook에 sass 설정하기(sass 에러 나는 경우) (0) | 2023.05.04 |
| [React+Typescript] Storybook에 Redux 설정하는 법 - could not found react-redux context value 에러 해결 (0) | 2023.05.03 |
| [React+Typescript] Storybook 도입하기 (0) | 2023.05.03 |
| [React] Notification custom hook 만들기 - 알림 아이콘, 알림음 설정 (0) | 2023.04.19 |
Comments