Translate

2021년 5월 20일 목요일

[React] TypeError: Cannot read property 'apply' of underfined (Redux DevTools 미설치 이슈)

 


증상 및 문제


증상1
 - 개발모드에서만 해당 증상이 나타나며, npm build 후 빌드된 소스에서는 증상이 발생하지 않는다.


증상2
 - 내 PC 에서 프로젝트 셋팅 후 구동 시 문제없이 동작이 된다.
 - 동료 PC 에서 소스를 내려받아 구동 시 Chrome 브라우저에서 아래와 같이 보여진다.



1004lucifer


이유 및 해결방안

TypeError: Cannot read property 'apply' of underfined 라는 메시지는 꼭 여기서만 나타나는게 아니라 다른 곳에서도 나오겠지만..

현재의 상황에서는 코드에서 개발환경인경우 'redux-devtools-extension' 을 사용하도록 셋팅한 경우에 위와 같은 증상이 발생한다.





Redux DevTools 설치하면 정상적으로 보여지게 된다.

https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?utm_source=chrome-ntp-icon





2021년 5월 16일 일요일

[React] ERROR - readonly keyword (Parsing error: Unexpected token, expected ":")

 


문제

yarn create react-app typescript-readonly_keyword-error --template typescript

위 명령어로 Typescript 형식의 React 프로젝트를 생성 후

프로젝트 셋팅 중 아래와 같은 에러가 나면서 페이지가 뜨지 않는 문제가 발생했다.

(아마 readonly 키워드를 변수명으로 잘못 인지해서 발생하는 에러로 보여진다.)



Failed to compile.

src\App.tsx
  Line 6:12:  Parsing error: Unexpected token, expected ":"

  5 |
  6 | export interface IRootState {
> 7 |   readonly loadingBar: any;
    |            ^
  8 | }
  9 |
  10| function App() {




원인 및 해결방법

- 아마 같은 증상이지만 원인이 다를 수 있다. 나의 경우에는 아래와 같았다.


package.json 파일을 수정하다가 eslintConfig 항목을 빠트렸더니 위와 같은 오류가 발생했으며, create-react-app 으로 처음 만들었을 때와 같이 eslintConfig 항목을 넣어줬더니 문제가 없어졌다.

https://github.com/1004lucifer/Test-JavaScript/blob/20ae946813d16fd6327ce5c9fcf5caa34a38cd95/React/TroubleShooting/typescript-readonly_keyword-error/package_origin.json#L25


아래의 GitHub 프로젝트를 수행하여 이슈를 직접 확인해볼 수 있다.
 - https://github.com/1004lucifer/Test-JavaScript/tree/master/React/TroubleShooting/typescript-readonly_keyword-error