FrontEnd/JavaScript
[ Node.js ] .js 파일에서 import 사용하기
SangHoonE
2022. 3. 15. 14:08
안녕하세요 상훈입니다.
node.js 를 이용한 백엔드 개발 중 .js 파일을 require 말고 import 시키고 싶었는데 안되었던 경험이 있으실 수 있습니다.
그때에는 package.json 혹은 eslintrc.json 파일의 parserOptions 항목을 살펴보셔야합니다.
ecmaVersion은 2016이상으로 맞춰주시길 바랍니다.
제 eslintrc.json 입니다.
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest"
},
sourceType: module 을 추가해주시거나, 변경해주시거나
package.json에서 type: 'module' 을 추가해주세요.
이제 import 를 사용하실 수 있습니다.
덤으로 export const ~ 도 사용하여 모듈식 출력이 가능해졌습니다.
도움이 되셨다면 광고 한번 클릭해주세요. 블로그 운영에 큰 힘이 됩니다. 감사합니다.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module' · Issue #462 · AtomLinter/linter-eslint
I get this error since the most recent update. is it possible there this is missing somewhere in the package?
github.com
반응형