Skip to content

CRA(Create React App)

Namjin Kim edited this page Dec 27, 2020 · 1 revision

CRA(Create React App)

문제 λ°œμƒ

11μ›” 23일 κΈ°μ€€ CRA 둜 react ν”„λ‘œμ νŠΈ 생성후 λΉŒλ“œ μ‹œ react-scripts:4.0.0μ—μ„œ μ•„λž˜ μ—λŸ¬κ°€ λ°œμƒν•˜κ³  μžˆλ‹€

TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'

μ•„λž˜ js νŒŒμΌμ—μ„œ ν•΄λ‹Ή μ—λŸ¬κ°€ λ°œμƒν•˜κ³  있으며 κ΄€λ ¨ ν‚€μ›Œλ“œ 검색 μ‹œ 문제 λ°œμƒ μ‹œκ° κΈ°μ€€ 24μ‹œκ°„ 이내에 μž‘μ„±λœ κ²Œμ‹œκΈ€μ—μ„œ 언급이 되고 μžˆλŠ” κ²ƒμœΌλ‘œ ν™•μΈλ˜μ—ˆλ‹€.

/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:239

  • ν•΄κ²°λ°©μ•ˆ

    이후 문제 해결에 차도가 μ—†λ‹€κ°€ 11μ›” 23일 2μ‹œ~3μ‹œ 사이 react-scripts 4.0.1 이 릴리즈 λ˜μ—ˆκ³  μ΅œμ‹  CRA의 μ˜μ‘΄μ„±μ΄ λ³€κ²½ λ˜μ—ˆλ‹€.

    6μ‹œμ— CRA둜 react ν”„λ‘œμ νŠΈ 생성 ν›„ λΉŒλ“œ κ²°κ³Ό 정상적인 νŽ˜μ΄μ§€ 응닡이 ν™•μΈλœλ‹€.

문제 λ°œμƒ

ν•˜μ§€λ§Œ μœ„μ˜ λ¬Έμ œμ— μ΄μ–΄μ„œ emotion 적용 μ‹œ μ•„λž˜μ™€ 같은 μ—λŸ¬κ°€ λ°œμƒν•œλ‹€.

CRA(Create%20React%20App)%200632f2eaf20046f9942d4a133e4407ef/Untitled.png

SyntaxError: pragma and pragmaFrag cannot be set when runtime is automatic.

  • μ‹œλ„

    ν•΄λ‹Ή μ—λŸ¬λ₯Ό κ²€μƒ‰ν•΄μ„œ 졜근 React17κ³Ό Emotion10 에 migrating λ¬Έμ œκ°€ μžˆλŠ” 것이 확인됐닀.

    Migrating to React 17 and Fixing the JSX Runtime Error with Emotion

    μœ„μ˜ κ²Œμ‹œκΈ€μ—μ„œ λͺ…μ‹œλœ λ°©μ•ˆμ„ μ μš©ν•œ κ²°κ³ΌλŠ” λ‹€μŒκ³Ό κ°™λ‹€.

    CRA(Create%20React%20App)%200632f2eaf20046f9942d4a133e4407ef/Untitled%201.png

    1번 λ°©μ•ˆ 적용 μ‹œ μ—λŸ¬

    CRA(Create%20React%20App)%200632f2eaf20046f9942d4a133e4407ef/Untitled%202.png

    2번 λ°©μ•ˆ 적용 μ‹œ μ—λŸ¬

    κ²°κ΅­ μœ„μ˜ λ°©μ•ˆμœΌλ‘œλŠ” 해결이 λ˜μ§€ μ•Šμ•˜λ‹€.

    λ˜ν•œ tsconfig.jsμ—μ„œ μ•„λž˜μ™€ 같은 κ²½κ³ λ₯Ό λ³΄μ΄λ©΄μ„œ jsx 값을 react 둜 λ°”κΎΌ μƒνƒœμ—μ„œ λΉŒλ“œ μ‹œ μžλ™μœΌλ‘œ react-jsx 둜 바꿔버린닀.

    Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'
    
    Cannot use JSX unless the '--jsx' flag is provided
    
  • ν•΄κ²°λ°©μ•ˆ

    λ‹€μŒ 두 링크λ₯Ό μ°Έκ³ ν•œλ‹€.

    μ•„λž˜ 링크에 μ˜ν•˜λ©΄ vs codeκ°€ intelliSenseλ₯Ό μœ„ν•΄ μ‚¬μš©ν•˜κ³  μžˆλŠ” typescript 버전과 node_modules에 μ„€μΉ˜λœ typescript 버전이 μΌμΉ˜ν•˜μ§€ μ•Šμ•„ λ°œμƒν•˜λŠ” 문제라고 ν•œλ‹€. κ·ΈλŸ¬λ―€λ‘œ μ•„λž˜ 두 λ°©μ•ˆ 쀑 ν•˜λ‚˜λ₯Ό μ μš©ν•œλ‹€.

    1. vs code ν•˜λ‹¨μ— ν‘œμ‹œλœ typescript 버전을 클릭해 node_modules의 λ²„μ „μœΌλ‘œ λ³€κ²½ν•œλ‹€.

    2. vs code의 typescript 버전에 맞좰 node_modules에 μ„€μΉ˜λœ typescript 버전을 λ‹€μš΄κ·Έλ ˆμ΄λ“œ ν•˜λ©΄ λœλ‹€.

    CRA(Create%20React%20App)%200632f2eaf20046f9942d4a133e4407ef/Untitled%203.png

    4.1.2 라고 ν‘œμ‹œλœ 뢀뢄이 vs codeμ—μ„œ μ‚¬μš©μ€‘μΈ TypeScript의 version 이닀.

    4.0.0 breaks with typescript (all versions) Β· Issue #9868 Β· facebook/create-react-app

    μ•„λž˜ 링크에 μ˜ν•˜λ©΄ ν•΄λ‹Ή μ—λŸ¬λŠ” eslint-import-resolver-node λͺ¨λ“ˆμ˜ λΆ€μž¬ λ•Œλ¬Έμ— 생긴거라고 ν•œλ‹€. npm i eslint-import-resolver-node λ₯Ό μž…λ ₯ν•΄ μ„€μΉ˜ν•˜λ„λ‘ ν•œλ‹€.

    SyntaxError: pragma and pragmaFrag cannot be set when runtime is automatic.

    Resolve error: unable to load resolver "node" Β· Issue #1730 Β· airbnb/javascript

문제 λ°œμƒ

μœ„λ₯Ό 톡해 문제λ₯Ό ν•΄κ²°ν–ˆλ”λ‹ˆ λ‹€μŒκ³Ό 같은 λ¬Έμ œκ°€ λ°œμƒν–ˆλ‹€.

Type '{ children: string; css: SerializedStyles; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLD  Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.  TS2322
  • ν•΄κ²°λ°©μ•ˆ

    μ•„λž˜ 링크에 μ˜ν•˜λ©΄ Emotion 11 버전을 μ‚¬μš©ν•  경우 tsconfig에 μ•„λž˜ μ˜΅μ…˜μ„ μΆ”κ°€ν•΄μ•Όν•œλ‹€κ³  ν•œλ‹€.

    {
       " compilerOptions " : {
         " types " : [ " @ emotion / react / types / css-prop " ]
      }
    }
    

    TS2322: Property 'css' does not exist... Β· Issue #1249 Β· emotion-js/emotion