let's get IT with DAVINA ๐Ÿ’ป

โ›”๏ธ ์ž์ฃผ ๋ณผ ์ˆ˜ ์žˆ๋Š” Errors ๋ณธ๋ฌธ

DEV_IN/TypeScript

โ›”๏ธ ์ž์ฃผ ๋ณผ ์ˆ˜ ์žˆ๋Š” Errors

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 2. 17. 19:14
import crypto from "crypto"
๐Ÿšซ Module “crypto” has no default export. (๊ฐ€์ ธ์˜ค๊ธฐ ๋ถˆ๊ฐ€๋Šฅ)

SOL 1.
import * as crypto from "crypto"โ€‹

 

SOL 2.
tsconfig.jsonํŒŒ์ผ๋กœ ๊ฐ€์„œ
esModuleInterop์„ true๋กœ ์„ค์ •
{
    "include": ["src"], //tsํŒŒ์ผ๋“ค์ด ์–ด๋””์— ์žˆ์–ด? ์ง€์ผœ๋ด
    "compilerOptions": {
        "outDir": "build", //ts->js๋กœ ์ปดํŒŒ์ผ๋œ๊ฑด ์–ด๋””์—๋‹ค ์ €์žฅํ• ๊บผ์•ผ?
        "target": "ES6", //js๋กœ ์ปดํŒŒ์ผ๋  ๋•Œ ์–ด๋–ค ๋ฒ„์ „์„ ์‚ฌ์šฉํ• ์ง€ ์„ ํƒ ๊ฐ€๋Šฅ (ES6 ์ ค ์ถ”์ฒœ)
        "lib": ["ES6"], //๋ธŒ๋ผ์šฐ์ € ํ™˜๊ฒฝ์ด ์•„๋‹Œ NodeJS์—์„œ ๊ฐœ๋ฐœํ• ๊ผฌ์ž„ dom ใ„ดใ„ด
        "strict": true,
        "esModuleInterop": true,
        "module": "CommonJS" //๋ธŒ๋ผ์šฐ์ €๋ฉด UMD
    }
}โ€‹
๐Ÿšซ Cannot find module “crypto” or its corresponding type declarations.
(ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์ž‘์„ฑ๋˜์ง€ ์•Š์€ ํŒจํ‚ค์ง€๋ฅผ importํ•  ๋•Œ, .d.tsํŒŒ์ผ์— ํƒ€์ž… ์ •์˜๋ฅผ ์ผ์ผ์ด ๋‹ค ์ ๊ณ  ์‹ถ์ง€ ์•Š์€ ๊ฒฝ์šฐ!)
SOLUTION 
npm i -D @types/nodeโ€‹

 

DefinitelyTyped
→ TypeScript type ์ •์˜๋ฅผ ์œ„ํ•œ repository
npm i [๋‚ด๊ฐ€ ์„ค์น˜ํ•  npmํŒจํ‚ค์ง€]
npm i -D @types/[๋‚ด๊ฐ€ ์„ค์น˜ํ•œ npmํŒจํ‚ค์ง€]โ€‹

 

'DEV_IN > TypeScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๊ธฐ์กด React์— TypeScript ์ ์šฉํ•˜๊ธฐ  (4) 2023.03.03
TypeScript(apply)  (2) 2023.02.17
TypeScript(Interface)  (4) 2023.02.16
TypeScript(Classes)  (4) 2023.02.12
TypeScript (Function)  (3) 2023.02.09
Comments