• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    해결됨

npm run dev 오류가 뜹니다

23.07.04 20:26 작성 23.07.04 21:07 수정 조회수 550

0

http://localhost:3000/에 뜬 오류

Server Error

TypeError: Cannot read properties of undefined (reading 'user')

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Source

components/AppLayout.js (15:52) @ eval


  13 | 
  14 | const AppLayout = ({ children }) => {
> 15 |     const isLoggedIn = useSelector((state) => state.user.isLoggedIn);
     |                                                    ^
  16 |     // const { isLoggedIn } = useSelector(state => state.user);
  17 | 
  18 |     return (
Call Stack
AppLayout

components/AppLayout.js (15:36)

Show collapsed frames

 

 

  • 터미널에 뜬 오류

TypeError: Cannot read properties of undefined (reading 'user')

at eval (webpack-internal:///./components/AppLayout.js:32:101)

at /Users/hyeonyeongjeong/Documents/2023project/nodebird/prepare/front/node_modules/react-redux/lib/hooks/useSelector.js:67:26

 

npm run dev를 하고

http://localhost:3000/ 들어갔더니

이런 오류가 뜨면서 안됩니다.

유저를 왜 읽지 못하는 걸까요?

오류 해결하고 싶습니다 ㅠ

 

답변 2

·

답변을 작성해보세요.

0

정현영님의 프로필

정현영

질문자

2023.07.06

삭제된 글입니다

아예 복사붙여넣기를 해보세요. 오타는 눈으로는 안 찾아집니다.

정현영님의 프로필

정현영

질문자

2023.07.06

다음강의에서 default: return state; 하라고 하셔서 하니까 오류 수정 됬어요 감사합니다!

아.. 이거 리덕스 실제 구현하기 강의 강의노트 보시면 나와있습니다. ㅠㅠ

0

리덕스가 제대로 연결되지 않은 것입니다. configureStore.js나 _app.js같이 리덕스 연결 관련 코드를 봐야합니다.

정현영님의 프로필

정현영

질문자

2023.07.05

image

app.js

import React from 'react';
import Head from 'next/head';
import PropTypes from 'prop-types';
import 'antd/dist/antd.css';
import wrapper from '../store/configureStore';

const NodeBird = ({ Component }) => {
  return (
    <>
      <Head>
        <title>NodeBird</title>
      </Head>
      <Component />
    </>
  );
};

NodeBird.propTypes = {
  Component: PropTypes.elementType.isRequired,
};

export default wrapper.withRedux(NodeBird);

코드입니다 어떤 문제가 있을까요?

 

package.json은 이렇습니다

강의에서는 리액트-리덕스만 설치했던거 같은데

리덕스를 제가 설치했는데 괜찮을까요?

{
  "name": "react-nodebird-front",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next"
  },
  "author": "winkberry",
  "license": "ISC",
  "dependencies": {
    "@ant-design/icons": "^5.1.4",
    "antd": "^4.24.10",
    "next": "^9.5.5",
    "next-redux-wrapper": "^6.0.2",
    "prop-types": "^15.8.1",
    "react": "^16.14.0",
    "react-dom": "^16.14.0",
    "react-redux": "^8.1.1",
    "redux": "^4.2.1",
    "styled-components": "^5.3.10"
  },
  "devDependencies": {
    "eslint": "^8.43.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-react": "^7.32.2",
    "eslint-plugin-react-hooks": "^4.6.0"
  }
}

 

https://github.com/ZeroCho/react-nodebird/tree/master/ch3/front

완성 코드는 여기인데 reducers 쪽까지 전부 확인해보세요. return같은 걸 빠뜨리셨을 수도 있습니다.

정현영님의 프로필

정현영

질문자

2023.07.06

다 살펴봤는데 오타가 하나도 없어요ㅠ 넥스트랑 리액트 버전도 강사님과 똑같이 변경했는데 여전히 유저를 읽지 못했다고 뜨네요 어떻게 하면 좋을까요?