2017-03-07 1 views
0
import React from 'react'; 
//import logo from './logo.svg'; 
import './App.css'; 
import '../public/components/NavBar'; 


class App extends React.Component { 
    render() { 
    return (
     <NavBar /> 
    ); 
    }; 
}; 

export default App; 

충분히 간단합니다. 왜 다음과 같은 컴파일 오류가 발생합니까?외부 디렉토리에서 React 구성 요소 가져 오기

Failed to compile. 

Error in ./src/App.js 

C:\Users\martin\Documents\Web Projects\ReactApp\app\src\App.js 
    10:9 error 'NavBar' is not defined react/jsx-no-undef 

✖ 1 problem (1 error, 0 warnings) 

Navbar의

import React, {Component} from 'react'; 

class NavBar extends Component { 
    handleClick() { 
    alert('Hello world!'); 
    } 

    render() { 
    return (
     <nav class="navbar navbar-default"> 
      <div class="container-fluid"> 
      <div class="navbar-header"> 
       <a class="navbar-brand" href="{this.handleClick}"> 
       Yeet Club 
       </a> 
      </div> 
      </div> 
     </nav> 
    ); 
    } 
} 

export default NavBar; 

답변

0

자바 스크립트 수입은 from하고 이름이 필요합니다

import NavBar from '../public/components/NavBar'; 
+0

나는 ./public/components/NavBar.js 모듈 구문 분석이''오류 C : \ Users \ martin \ Documents \ Web Projects \ ReactApp \ app \ public \ components \ NavBar.js 예기치 않은 토큰 (10 : 2) 적절한 l 이 파일 형식을 처리 할 수 ​​있습니다. SyntaxError : 예기치 않은 토큰 (10 : 2) @ ./src/App.js 16 : 14-52'' – santafebound

+0

위의 NavBar 코드가 포함되어 있습니다. 나는 여전히 문제가 Component와 Component 코드를 가져 오는 것이라고 생각한다. 이 구성 요소는 src/폴더에 포함되어있을 때 잘 작동합니다 ... – santafebound

관련 문제