SyntaxError: Cannot use import statement outside a module 해결
import 방법으로 외부 라이브러리를 불러올 때, 해당 문구를 출력하며, import 라이브러리를 불러오지 못하는 경우가 발생했다.
package.json
파일에 가서 "type":"module"
을 추가해줍니다, 이는 script
방식으로 불러오는 것으로 기본값이 set되어 있어서, module 방식으로 바꿔준 것 입니다.
package.json 파일
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"web3": "^1.7.0"
},
"type": "module"
}
기존에 import 방식을 script로 진행했기 때문에 발생한 오류
다시 실행해보니, 잘 해결되었습니다!
'etc > 개발하다가 만난 삽질' 카테고리의 다른 글
hyper-v 우분투, 해상도 크기제한 풀기 (0) | 2023.03.04 |
---|---|
file is a commonjs module it may be converted to an es6 module 해결 (0) | 2022.02.03 |
[LInux] bash shell export (환경변수) (0) | 2022.01.13 |
ssh - 추가인증 google authenticator (PAM) (0) | 2022.01.07 |
Shell - 명령어 출력에서 단어 찾기 (0) | 2022.01.06 |