2017-12-22 38 views
0

create-react-appField Declarationcreate-react-app을 사용하고 있습니다. 불행하게도, 여기 내 코드에서 사용됩니다create-react-app에서 필드 선언을 사용할 때 오류가 발생했습니다.

Failed to compile.

./src/App.js Line 5: 'state' is not defined no-undef

Search for the keywords to learn more about each error.

왜 내가 필드 선언 구문을 사용할 수 없습니다

// ./src/App.js 
import React, {Component} from 'react'; 
import ListContacts from './ListContacts'; 

class App extends Component { 
    state = { 
    contacts: [ 
     { 
     id: 'bob', 
     name: 'bob bob', 
     email: '[email protected]', 
     avatarURL: 'http://localhost:5001/bob.jpg' 
     }, 
     { 
     id: 'michael', 
     name: 'Michael', 
     email: '[email protected]', 
     avatarURL: 'http://localhost:5001/michael.jpg' 
     }, 
     { 
     id: 'ash', 
     name: 'Ash', 
     email: '[email protected]', 
     avatarURL: 'http://localhost:5001/ash.jpg' 
     } 
    ] 
    } 

    render() { 
    return (
     <div> 
     <ListContacts contacts={this.state.contacts} /> 
     </div> 
    ); 
    } 
} 

export default App; 

불행하게도, 나는 오류가? 나는 다른 사람들이 프로젝트와 코드를 실행하도록했으며 시스템에서 잘 작동한다.

+0

프로젝트에서 사용중인 eslint 버전은 무엇입니까? – JMA

+0

방금 ​​v4.13.1로 업데이트되었습니다 (방금 오늘 아침 업데이트되었습니다). 내 셸을 다시 시작하고 동일한 오류가 발생합니다. – HelloWorld

답변

0

사용중인 eslint 버전 때문일 수 있습니다. 어떤 경우에는

/*eslint-disable no-undef*/ 
... 
/*eslint-enable no-undef*/ 

또는 다음과 같은 문제가없는 다른 eslint 버전을 사용하여 코드를 래핑하여 문제를 해결할 수 있습니다.