250x250
Notice
Recent Posts
Recent Comments
Link
\(@^0^@)/
TypeScript : Cannot find name 'console' Error ๋ณธ๋ฌธ
728x90
๐ฃ ์๋ฌ ๋ฐ๊ฒฌ ์์ธ
function printName(firstName: string, lastName?: string) {
console.log(firstName);
console.log(lastName);
}
printName("amy", "park");
printName("amy"); // undefined
printName("amy", undefined); // Optional parameter
ts-node 1-2-function.ts
ts-node๋ฅผ ํตํด, ๋ด๊ฐ ์์ฑํ ์ฝ๋๋ฅผ ์ฝ์๋ก ์ฐ์ด์ ํ์ธํ๋ ค ํ๋๋ฐ, error ๋ฐ์ํ์๋ค.
๐คฉ 1. runtime์ด Node.js์ธ ๊ฒฝ์ฐ ํด๊ฒฐ๋ฒ
npm i -D @types/node
ํ์ฌ ๋ด๊ฐ ์์ฑํ๊ณ ์๋ 1-2-function์ ์์ ํด๋์ด๊ธฐ์,
๊ทธ๋ณด๋ค ๋ ์์์ธ typescript ํด๋์ ์์ ์ฝ๋๋ฅผ ์ถ๊ฐํ์ฌ ์๋ฌ ํด๊ฒฐ.
๐คฉ 2. ๋ธ๋ผ์ฐ์ ์์ ์ฝ๋๋ฅผ ์คํํ๋ ๊ฒฝ์ฐ ํด๊ฒฐ๋ฒ
'lib' ์ปดํ์ผ๋ฌ ์ต์ ์ 'dom'์ ํฌํจํ๊ฒ ๋ณ๊ฒฝํด๋ณด๋ ๋ฐฉ๋ฒ๋ ์์.
{
"compilerOptions": {
"lib": [
// ... your other libs
"dom"
],
// ... rest
},
}
๐คฉ 3. ์ตํ์ ๋ฐฉ๋ฒ
node_modules์ package-lock.json ํ์ผ์ ์ญ์ ํ๊ณ , npm install๋ก vscode๋ฅผ ์ฌ์คํ์ํจ๋ค.
rm -rf node_modules package-lock.json
npm install
728x90
'์๋ฌ๋ ธํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
TypeScript : Uncaught ReferenceError: exports is not defined (0) | 2022.03.10 |
---|---|
prettier ์๋ฌ๋ ๋ (0) | 2022.02.19 |
[Error] Unhandled Rejection (TypeError): Cannot read properties of undefined (0) | 2021.12.13 |
Git push error (0) | 2021.10.15 |