2017-09-19 3 views
6

supposed to support module loadingimport 인 Chrome 61을 실행 중입니다.크롬 61 : 예기치 않은 토큰 가져 오기

실제로 Paul의 demo은 저에게 효과적입니다. 그러나 직접 시도 할 때 JS 오류 "예기치 않은 토큰 가져 오기"가 발생합니다. 크롬은 import 망설 것 같습니다 :

test.html를

<!doctype html> 
<html> 
<body> 
<script src="test.js"></script> 
</body> 
</html> 

test.js :

import {hello} from './something.js' 
console.log(hello()) 

something.js이

export {hello} 
function hello() { 
    return "hello world" 
} 

왜 크롬은 "수입"을 이해하지 않습니다

답변

9

<script type=module src=test.js>이어야합니다. 전체 구문은 모듈 스크립트에서 약간 변경됩니다 (importexport이 허용되며 엄격 모드가 필수 항목 임).

+3

이 코드는 type = module을 사용할 때 유용합니다. 그럼에도 불구하고 Chrome 개발자 도구는 파일을 편집 할 때 test.js에서 "Uncaught Syntax 오류 : 예기치 않은 토큰 {"오류를 표시합니다. 어떤 생각을 어떻게 극복 할 수 있을까요? – Stefan

+0

@Stefan Chrome v64 개발자 도구 디버거는 여전히 가져 오기 및 내보내기에 문제가 있습니다. – Optimax

관련 문제