file is a commonjs module it may be converted to an es6 module
자바스크립트를 쓰다가 이런 경고를 봤을 것이다, 보통 자바스크립트에서 require
나 import
의 키워드를 통해서 외부 라이브러리를 불러오게됩니다. 이때 require
을 쓰면, 이러한 문구를 보게 됩니다.
알림 문구를 없애고 싶다면 두가지, 총 2가지 방법이 존재합니다.
settings.json
파일에 설정값을 변경import
로 대체하는 방법
1. settings.json
"typescript.suggestionActions.enabled": false
"javascript.suggestionActions.enabled": false
제안을 보지 않게 합니다, 하지만 이는 이 알림 문구 이외에 다른 문구들의 제안을 보지 못하기 때문에, 유의해야 합니다.
2. import
import Web from "web3"
import로 대체 시, Cannot use import statement outside a module
이라는 SyntaxError
가 나올 수 있습니다.
해당 파일에서는 package.json
파일에 "type": "module"
의 문구를 추가해주면 됩니다.
{
"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
와 경고문구를 해결하여 사용할 수 있습니다.
'etc > 개발하다가 만난 삽질' 카테고리의 다른 글
hyper-v 우분투, 해상도 크기제한 풀기 (0) | 2023.03.04 |
---|---|
SyntaxError: Cannot use import statement outside a 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 |