typescript
typescript-eslint 'console' is not defined no-undef 에러해결
선물공룡디보
2024. 12. 22. 23:44
'console' is not defined no-undef 에러해결
eslint 에서 tseslint 설정 추가를 하던 도중 다음과 같은 에러가 발생하였다.
에러가 난 코드는 다음과 같다.
test.ts
class Test {
constructor() {
console.debug('test');
}
}
new Test();
문제 원인
eslint 에서는 console 메서드를 사용하지 않는것을 권장 한다고 한다.
공식문서 https://eslint.org/docs/latest/rules/no-console#rule-details
해결방법
eslint.config 설정 파일에 rules 에 다음과 같이 "no-console" : "off"를 추가하면 된다.
경고만 뜨게 하고 싶다면 'warn'을 추가하면 된다.
eslint.config.mjs
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
"no-console": "off"
}
}
);