Inflearn brand logo image

인프런 커뮤니티 질문&답변

noel75님의 프로필 이미지
noel75

작성한 질문수

처음 만난 리액트(React)

jsx 코드 작성해보기에서 index.js 수정 후 에러 뜹니다.

작성

·

284

1

ERROR in ./src/chapter_03/Library.jsx 5:0-24

Module not found: Error: Can't resolve 'Book' in '/../my-react1/src/chapter_03'

Did you mean './Book'?

Requests that should resolve in the current directory need to start with './'.

Requests that start with a name are treated as module requests and resolve within module directories (node_modules, /../my-react1/node_modules).

If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
어떻게 해야 할까요?

답변 3

1

noel75님의 프로필 이미지
noel75
질문자

아.. 그렇게 하니 오류 안나옵니다.
감사합니다!

0

noel75님의 프로필 이미지
noel75
질문자

네, 아래와 같습니다.

import React from "react";
import Book from 'Book';

function Library(props){
    return(
        <div>
            <Book name="처음 만난 파이썬" numOfPage={300} />
            <Book name="처음 만난 AWS" numOfPage={400} />
            <Book name="처음 만난 리액트" numOfPage={500} />
        </div>
    );
}

export default Library;
Inje Lee (소플)님의 프로필 이미지
Inje Lee (소플)
지식공유자

Book.jsx 파일을 같은 폴더에 작성하셨는지는 모르겠는데,

만약 Library.jsx 파일과 같은 경로에 작성했다면 아래와 같이 import 하셔야 합니다.

import Book from './Book';

0

Inje Lee (소플)님의 프로필 이미지
Inje Lee (소플)
지식공유자

안녕하세요, 소플입니다.

 

혹시 작성하신 Library.jsx 파일 소스 코드를 첨부해주실 수 있을까요?

 

감사합니다.

noel75님의 프로필 이미지
noel75

작성한 질문수

질문하기