2017-12-29 9 views
1

에 예기치 않은 식별자가 나는 오류catch되지 않은 구문 에러 : "가져 오기"의 구문와의 js 파일을 가져올하려고 할 때 "경로에서 수입 X"

"Uncaught SyntaxError: Unexpected identifier app.js:2" 

를 얻을. 나는이 구문을 사용한 적이 없지만 자습서의 코드를 복사 했으므로 제대로 작동하지 않습니다. 모든 JS 파일이 같은 "JS"폴더에있는

된 index.html은

<!DOCTYPE html> 
<html> 
<head> 
    <title>game 1</title> 
     <script type="text/javascript" src="js/phaser.min.js"></script> 
     <script type="text/javascript" src="js/app.js"></script> 
</head> 
    <div id="game"> 

    </div> 

<body> 

</body> 

export default class Boot { 
    preload() { 
    this.load.image('preloader', '../img/loading_bar.png'); 
    } 
    create() { 
    this.game.input.maxPointers = 1; 
    this.game.state.start('preload'); 
    } 
} 

var game; 
import Boot from 'Boot.js'; 
import Preload from 'Preload.js'; 
import Game from 'Game.js'; 


window.onload = function() { 
    game = new Phaser.Game(800, 600, Phaser.AUTO, 'game'); 
    game.state.add('boot', Boot); 
    game.state.add('preload', Preload); 
    game.state.add('game', Game); 
    game.state.start('boot'); 
}; 

Boot.js을 app.js 어떤 도움? 감사!

+2

브라우저에서'import'가 작동하지 않습니다. 파일 시스템의 로컬 파일과 함께 작동합니다. 브라우저에서 이해할 수있는 바닐라 자바 ​​스크립트로 소스 코드를 컴파일하려면 바벨 (babel)을 사용해야합니다. 이것은 종종 Webpack으로 수행됩니다. 추천 읽기 : https://blog.andrewray.me/webpack-when-to-use-and-why/ –

+0

@AndyRay 더 이상 완전히 사실이 아닙니다 ~ https://matthewphillips.info/posts/loading-app-with- 스크립트 모듈 – Phil

+0

FYI : 가져 오기 문은 모든 절차 코드 앞에 와야합니다. 당신은 당신의 스크립트 상단에'var game'을 가지고 있습니다. – Phil

답변

-2

";"을 (를) 제거해야합니다. after app.js file}