You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
서버를 실행하였을 때 다음과 같은 에러가 계속 발생하여 해결책을 계속 찾아보다 React-router 공식 문서를 참조해보니 StaticRouter를 가져오는 라이브러리가 변경됬다는 것을 알 수 있었습니다.
import { StaticRouter } from "react-router-dom" => import { StaticRouter } from "react-router-dom/server"
Before
importReactfrom"react";importReactDOMServerfrom"react-dom/server";importexpressfrom"express";import{StaticRouter}from"react-router-dom";importAppfrom"./App";constapp=express();// 서버 사이드 렌더링을 처리할 핸들러 함수이다.// 이 함수는 404가 떠야 하는 상황에 404를 띄우지 않고 서버 사이드 렌더링을 해준다.constserverRender=(req,res,next)=>{constcontext={};constjsx=(<StaticRouterlocation={req.url}><App/>;
</StaticRouter>);constroot=ReactDOMServer.renderToString(jsx);// 렌더링을 하고res.send(root);// 클라이언트에게 결과물을 응답한다.};// 위 함수를 서버에 적용app.use(serverRender);app.listen(5000,()=>{console.log("Running on http://localhost 5000");});
After
importReactfrom"react";importReactDOMServerfrom"react-dom/server";importexpressfrom"express";import{StaticRouter}from"react-router-dom/server";// react-router-dom/serverimportAppfrom"./App";constapp=express();// 서버 사이드 렌더링을 처리할 핸들러 함수이다.// 이 함수는 404가 떠야 하는 상황에 404를 띄우지 않고 서버 사이드 렌더링을 해준다.constserverRender=(req,res,next)=>{constcontext={};constjsx=(<StaticRouterlocation={req.url}><App/>;
</StaticRouter>);constroot=ReactDOMServer.renderToString(jsx);// 렌더링을 하고res.send(root);// 클라이언트에게 결과물을 응답한다.};// 위 함수를 서버에 적용app.use(serverRender);app.listen(5000,()=>{console.log("Running on http://localhost 5000");});
Conclusion about issue
import { StaticRouter } from "react-router-dom" => import { StaticRouter } from "react-router-dom/server"
react-router v6로 업그레이드 되면서 변경된 사항이었습니다.
저와 같은 이슈를 겪고 있는 분께 도움이 되길 바랍니다.^^
Thank you, velopert!
The text was updated successfully, but these errors were encountered:
StaticRotuer 가져오기
Error
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
서버를 실행하였을 때 다음과 같은 에러가 계속 발생하여 해결책을 계속 찾아보다
React-router 공식 문서를 참조해보니 StaticRouter를 가져오는 라이브러리가 변경됬다는 것을 알 수 있었습니다.
import { StaticRouter } from "react-router-dom"
=>import { StaticRouter } from "react-router-dom/server"
Before
After
Conclusion about issue
import { StaticRouter } from "react-router-dom"
=>import { StaticRouter } from "react-router-dom/server"
react-router v6로 업그레이드 되면서 변경된 사항이었습니다.
저와 같은 이슈를 겪고 있는 분께 도움이 되길 바랍니다.^^
Thank you, velopert!
The text was updated successfully, but these errors were encountered: