๋ด ์ฑ์ react-scripts 3.4.4์์ 4.0.0์ผ๋ก ์
๊ทธ๋ ์ด๋ ํ ํ ์ฑ์ด IE11์์ ์ ํ ์๋ํ์ง ์๋ ๊ฒ์ ํ์ธํ์ต๋๋ค.
๋ํ ์ต์ CRA์์ ์ ์ฑ์ ๋ง๋ค์์ ๋ react-app-polyfill
์ถ๊ฐํ๋๋ฐ ์ ํ ์๋ํ์ง ์๋ ๊ฒ์ผ๋ก ๋ํ๋ฌ์ต๋๋ค.
๋ด package.json
์ (๋) ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
{
"name": "cra4",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"react": "^17.0.1",
"react-app-polyfill": "2.0.0",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
">0.2%",
"not dead",
"not op_mini all"
]
}
}
yarn build
ํ๊ณ build/
๋๋ ํฐ๋ฆฌ์์ ์ ๊ณต ํ ๋๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ํ๋ฉ๋๋ค.
๊ธฐ๋ณธ CRA ๋์์ ๋๋ค.
(ํด๋น๋๋ ๊ฒฝ์ฐ ์ฌ๊ธฐ์ ๋ต๋ณ์ ์์ฑํ์ญ์์ค.)
Environment Info:
current version of create-react-app: 3.4.1
running from C:\Users\XXX\AppData\Local\Yarn\Data\global\node_modules\create-react-app
System:
OS: Windows 10 10.0.19041
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Binaries:
Node: 14.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.19041.423.0
Internet Explorer: 11.0.19041.1
npmPackages:
react: ^17.0.1 => 17.0.1
react-dom: ^17.0.1 => 17.0.1
react-scripts: 4.0.0 => 4.0.0
npmGlobalPackages:
create-react-app: Not Found
yarn add react-app-polyfill
import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable';
์ ์๋จ์ index.tsx
yarn start
์ฌ์ดํธ๊ฐ ์๋ํด์ผํฉ๋๋ค (๊ธฐ์ ์ ๊ธฐ๋ํ์ง ์์ต๋๋ค. ์ ์ฒด์ ์ผ๋ก IE์ด์ง๋ง ๋น ํ์ด์ง๋ ๋งค์ฐ ๋์ฉ๋๋ค)
(์์ ํ๋ก์ ํธ์ ๋ํ ๋งํฌ์ ์ ํํ ์ง์นจ์ ๋ถ์ฌ ๋ฃ์ด ๋ฌธ์ ๋ฅผ ์ฌํํ์ญ์์ค.)
์ด ๋จ๊ณ๋ฅผ ๊ฑด๋ ๋ฐ๋ฉด ์ด๋ป๊ฒ๋ฉ๋๊น? ์ฐ๋ฆฌ๋ ๋น์ ์ ๋๊ธฐ ์ํด ๋ ธ๋ ฅํ ๊ฒ์ด์ง๋ง ๋ง์ ๊ฒฝ์ฐ ์ค์ํ ์ ๋ณด๊ฐ ๋๋ฝ๋์ด ๋ถ๊ฐ๋ฅํฉ๋๋ค. ์ด ๊ฒฝ์ฐ ์ฐ์ ์์๊ฐ ๋ฎ์ ๋ฌธ์ ์ ํ๊ทธ๋ฅผ ์ง์ ํ๊ณ ๋ช ํํ ๋ฐฉํฅ์ด ์์ผ๋ฉด ๊ฒฐ๊ตญ ์ข ๋ฃํฉ๋๋ค. ๊ฒฐ๊ตญ ๋ค๋ฅธ ๋๊ตฐ๊ฐ๊ฐ ์ด์ ๋ํ ์ฌํ ๊ฐ๋ฅํ ์๋ฅผ ๋ง๋ค ์ ์๊ธฐ ๋๋ฌธ์ ์ฐ๋ฆฌ๋ ์ฌ์ ํ ๋ณด๊ณ ์์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๋์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!๋ด๊ฐ ์ฐฉ๊ฐํ์ง ์์ผ๋ฉด browserslist
๊ตฌ์ฑ์ผ๋ก ์ธํด ๊ฐ๋ฐ ๋ชจ๋์์ ์ ํ๋ก์ ํธ๊ฐ IE์์ ์ ํ ์๋ํ์ง ์์ต๋๋ค.
( package.json
).
ํผ์๋ฅด๋
์, ๋๋ฝ ๋ ์ ๋ณด๋ก ๋ฌธ์ ๋ฅผ ์
๋ฐ์ดํธํ์ต๋๋ค.
IE11์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์ง์๋์ง ์๋๋ค๋ ๊ฒ์ ์์์ง๋ง react-app-polyfill
๋ ์๋ํ์ง ์์ต๋๋ค.
+, ํ๋ก๋์
๋น๋์ ๋ํ ๋์ผํ ๋ฌธ์
https://reactjs.org/docs/error-decoder.html/?invariant=31&args [] = object % 20with % 20keys % 20 % 7B % 24 % 24typeof % 2C % 20type % 2C % 20key % 2C % 20ref % 2C % 20props % 2C % 20_owner % 7D
๋ด ํด๊ฒฐ ๋ฐฉ๋ฒ :
import 'react-app-polyfill/ie11';
// import 'react-app-polyfill/stable';
import 'core-js/stable';
import 'regenerator-runtime/runtime';
๋๋์ด ๋ฌธ์ ์ ์ํฅ์๋ฐ์ต๋๋ค.
@ezBill ์๋ฃจ์
์ด ์ ์๊ฒ
react-app-polyfill
์ (๋ฅผ) ์์ ํด์ผํฉ๋๊น?
@ezBill ์๋ฃจ์ ์ด ์ ์๊ฒ
+1
ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์๋ํ์ง ์๊ณ ์ค๋ฅ๊ฐ ๋จ์ ์์ต๋๋ค.
๋ด polyfill์ ๋ค์๊ณผ ๊ฐ์ด ๋ณด์ด๊ณ IE11์๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
import "react-app-polyfill/ie11";
import "react-app-polyfill/stable";
์ด๋ฌํ ํด๋ฆฌ ํ์ด ์ ์๋ฆฌ์ ์์ผ๋ฉด ๊นจ์ง ์์๋ ๋ค๋ฅธ ๊ฐ์ ธ ์ค๊ธฐ๋ณด๋ค ์ฐ์ ํด์ผํฉ๋๋ค. ๋ํ polyfill์ TextEncoder
์ ๊ฐ์ ๋ ๋ง์ ๋ํดํ API๋ฅผ ์ ๊ณตํ์ง ์์ผ๋ฏ๋ก ์ด๋ค ์ด์ ๋ก ํ์ํ ๊ฒฝ์ฐ polyfill์๋ก๋ํด์ผํฉ๋๋ค.
์๋ก์ด jsx ๋ณํ์ด์ด ๋ฌธ์ ์ ์์ธ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. polyfill์ ๊ฐ์ ธ ์ค๋ ์ฃผ index.js ์๋จ์ /** <strong i="5">@jsxRuntime</strong> classic */
์ ์ถ๊ฐํ๊ฑฐ๋ DISABLE_NEW_JSX_TRANSFORM=true
ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ์ฌ ๋นํ์ฑํํ์ญ์์ค. ์ ๊ฒฝ์ฐ์๋ ๋ ์ค ํ๋๊ฐ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํฉ๋๋ค.
๋ด ์๊ฐ ์ ํด๋ฆฌ ํ์ ๋จผ์ ๊ฐ์ ธ ์ค๋ฉด ๋ฐ์ํ๊ธฐ ์ ์๋ก๋ ํ ์ ์์ง๋ง ์ปดํ์ผ๋ฌ๊ฐ ์ฝ์
ํ๋ import {jsx as _jsx} from 'react/jsx-runtime';
์ค ์ ์๋ก๋ ํ ์๋ ์์ต๋๋ค.
@msbarry ์ฌ๊ธฐ์์ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์์ ํ์ธํ ์ ์์ต๋๋ค. ๋์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
์ฐ๋ฆฌ๋์ด ๊ฐ์ ๋ฌธ์ ์ ๋ถ๋ช ํ์ต๋๋ค. ์ฐ๋ฆฌ๋ ์ด๋ฏธ ๋ง์ ์ฝ๋๋ฒ ์ด์ค๋ฅผ ์๋ก์ด JSX ํ์ ( React
๋ ์ด์ ๊ฐ์ ธ์ฌ ํ์๊ฐ์๋ ํ์)์ผ๋ก ๋ณํํ์ต๋๋ค.
์ข์ ์์! ์๋ก์ด JSX ๊ตฌ๋ฌธ์ ๋ชจ๋ ์ ์งํ ์์์์ต๋๋ค!
์ฐ๋ฆฌ๋ src/index.js
ํ์ผ์ ์๋จ์๋ง ์ด๊ฒ์ ์ ์ฉํด์ผํ์ต๋๋ค.
/** <strong i="10">@jsxRuntime</strong> classic */
import 'react-app-polyfill/ie11'
// IE11 needs "jsxRuntime classic" for this initial file which means that "React" needs to be in scope
// https://github.com/facebook/create-react-app/issues/9906
import React from 'react'
๊ทธ๋ ์ง ์์ผ๋ฉด ์ฌ๋๋ค์ด ์ดํดํ์ง ๋ชปํ ๊ฒ์ด๊ณ ์๋ง๋ ์ฝ๋๋ฒ ์ด์ค์ ์์ํ ๋จธ๋ฌผ๊ฒ ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ฃผ์์ ์ถ๊ฐํ์ต๋๋ค.
์ ์ผํ ๋จ์ ์ ํธ๋ฆฌ ์์ดํน์ด ๋ฒ๋ค ํฌ๊ธฐ๋ฅผ ์ค์ด์ง ์๋๋ค๋ ๊ฒ์ธ๋ฐ, ์ด๋ ์ฒ์์ React 17๋ก ์ ๊ทธ๋ ์ด๋ ํ ์ฃผ์ ์ด์ ์ค ํ๋์์ต๋๋ค.
FWIW๋ index.ts
ํ์ผ์ init.ts
๋ฐ main.tsx
ํ์ผ๋ก ๋ถํ ํฉ๋๋ค. ์ฌ๊ธฐ์ init.ts
๋ชจ๋ ๊ด๋ จ ํด๋ฆฌ ํ์ ๊ฐ์ ธ์ค๊ณ main.tsx
๋ ์ค์ ์ง์
์ ์
๋๋ค ( React ์ฝ๋ ํฌํจ) ๋ฐ index.ts
๋ ๋ ๋ค ์์๋๋ก ๊ฐ์ ธ์ต๋๋ค. ์ด๋ ๊ฒํ๋ฉด ํด๋ฆฌ ํ์ด ์ ์ฉ๋์ด์ผํ๋ ๋ชจ๋ ๋ชจ๋์ด ํด๋ฆฌ ํ ํ์๋ก๋๋๊ณ ์ด๋ฆ ์ง์ ์ ํตํด ๊ฐ์ ธ ์ค๊ธฐ์ ์๋ ์ ๋ ฌ์ ์ฌ์ฉํ ๋๋ ํด๋ฆฌ ํ์ด ๊ธฐ๋ณธ ์ง์
์ ์์ ์ค๋๋ก ๋ณด์ฅํฉ๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฒ๋ณด๋ค ๋ ์คํ ๊ฐ๋ฅํ ์๋ฃจ์ ์ผ ์ ์์ต๋๋ค.
์์ ์ด๋ ๊ฒ๋ ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
IE11 ์ค๋ฅ
์ค๋ฅ๋ฅผ ํด๋ฆญํ๋ฉด ์ฌ๊ธฐ๋ก ์ด๋ํฉ๋๋ค.
IE ๋ฒ์
๋ค์์ ์ฌํํ๋ ์์ฃผ ๊ฐ๋จํ ์์ ๋๋ค.
npx create-react-app ie11app
yarn add react-app-polyfill
index.js
์
๋ฐ์ดํธ/** <strong i="23">@jsxRuntime</strong> classic */
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<div>Come on</div>,
document.getElementById('root')
);
ie 11
์ browerslist
์์ package.json
{
"name": "ie11app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-app-polyfill": "^2.0.0",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"ie 11"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}
}
yarn start
index.js์์ import 'react-app-polyfill/stable';
๋ฅผ ์ ๊ฑฐํด๋ณด์ธ์.
import 'react-app-polyfill/ie11'
๋ง ์์ผ๋ฉด๋ฉ๋๋ค.
๊ทธ๊ฒ์ polyfill ๋ฌธ์ ์ฒ๋ผ ๋ณด์ด์ง ์์ต๋๋ค. ๋๋ฒ๊ฑฐ์ ํ์๋๋ ์ฝ๋๋ ES5๊ฐ ์๋๋ฉฐ, IE11์์ ์ง์ํ์ง ์๋ ๋น ๊ตฌ์กฐํ ๋ฐ ๊ธฐ๋ณธ ์ธ์๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์ฌ์ฉํด๋ณด์ญ์์ค "ie >= 11"
๋น์ ์ browserslist
๋์ "ie 11"
. ๋ ๊ตฌ๋ฌธ์ด ์๋ํ๋์ง ํ์คํ์ง ์์ต๋๋ค.
@ Dan503 @pluma "ie >= 11"
๋ฐ import 'react-app-polyfill/stable';
์ ๊ฑฐ๋ฅผ ๋ชจ๋ ์๋ํ์ง๋ง ์ฌ์ ํ ์ด์ด ์์ต๋๋ค.
๋น์ ์ ๋๋ฌด ์น์ ํ๊ณ ์๋ก์ด npx create-react-app ie11app
๋ง๋ค๊ณ ๊ทธ๊ฒ์ด ์ค์ ๋ก IE11์์ ์ฌ์ ํ ์๋ํ๋์ง ํ์ธํ ์ ์์ต๋๊น?
๊ฐ์ฌํฉ๋๋ค
์ต์ ์ ๋ณด:
"react-scripts": "^3.0.0"
๋ ๋๋ฆฌ๋ฉด IE 11
์์๋ "react": "^17.0.1",
ํ์ง๋ง "react-scripts": "4.0.0"
์ (๋) ์ฌ์ ํ ๋์๊ฒ ์์๋์์ต๋๋ค.
๋๋ ๋ํ ์ด๋ฌํ ์๋ฃจ์
์ค ๋ง์ ๊ฒ์ ์๋ํ์ต๋๋ค. ์๋ํ๋ ์ ์ผํ ๋ฐฉ๋ฒ์ react-scripts
์ 3.4.4
๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํ๋ ๊ฒ์
๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
+, ํ๋ก๋์ ๋น๋์ ๋ํ ๋์ผํ ๋ฌธ์
https://reactjs.org/docs/error-decoder.html/?invariant=31&args [] = object % 20with % 20keys % 20 % 7B % 24 % 24typeof % 2C % 20type % 2C % 20key % 2C % 20ref % 2C % 20props % 2C % 20_owner % 7D