개발자/node js
Yarn 쓰는 법
YoungDogg
2022. 1. 10. 18:40
Yarn을 쓴 이유 : node를 쓰면서 import 오류가 떴다. yarn을 쓰면 된다고 했다. yarn을 써보자.
※윈도우에선 cmd로 해야 한다. powershell은 권한 오류가 뜬다
import {checkValidationPhone, getToken, sendToken2SMS} from './phone.js'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
yarn 설치법
win) cmd 관리자 권한 실행 -> npm install -g yarn -> 버전 확인 yarn --version
Installation | Yarn - Package Manager (yarnpkg.com)
Installation
Yarn's in-depth installation guide.
yarnpkg.com
yarn init : 제이슨 파일을 만든다.
C:\Users\내가 쓰고 싶은 경로\class\01-05-token-count-api-facade-import>yarn init
yarn init v1.22.17
question name (01-05-token-count-api-facade-import):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private:
success Saved package.json
Done in 4.44s.
type, script " 추가 : 제이슨 파일에서 type과 script를 추가한다.
{
"name": "01-05-token-count-api-facade-import",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"scripts": {
"dev": "node index.js"
}
}
성공
C:\Users\내가 쓰고 싶은 경로\class\01-05-token-count-api-facade-import>yarn dev
yarn run v1.22.17
$ node index.js
01033334444 번호로 인증번호 118848를 전송합니다
Done in 0.18s.