ES2015(ES6) 모듈 사용시 *.mjs 파일을 import 하려고 하면 에러 발생

 

* 소스

import * as lib from './lib.mjs';

 


* 에러 메시지
Failed to load module script: The server responded with a non-JavaScript MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.


*  해결 방법

    - 웹서버의 MIME type 설정 변경

    - nginx 웹 서버를 사용하고 있는 경우


nginx/conf/mime.types 파일 수정
    - 다음을 추가
application/javascript                mjs;

 


    - 서버 재시작
sudo service nginx restart

 

   - 브라우저 캐시 삭제후 접속

반응형

'Code > JavaScript' 카테고리의 다른 글

[Javascript] gulp 사용법  (0) 2019.07.28
[Javascript] webpack 사용법  (0) 2019.07.28
[Vue.js] Nuxt.js  (0) 2019.07.23
[Javascript] axios (ajax)  (0) 2019.07.22
[Javascript] fetch (ajax)  (0) 2019.07.22
Posted by codens