λ΄ μ±μμ μ€λ₯λ₯Ό μμ νκΈ° μν΄ IE11μ μ§μνλ €κ³ ν©λλ€.
TypeError: Object doesn't support property or method 'find'
λ€μ 2.4.6
νμ§λ§ μ΅μ λ² νμμλ μλνμ§ μμ
λ€μ ꡬμ±μΌλ‘ babel-preset-env
μ ν¨κ» μ¬μ©μ μ§μ .babelercλ₯Ό μΆκ°νμ΅λλ€.
{
"presets": [
"es2015",
"react",
"next/babel",
"stage-0",
[ "env", {
"targets": {
"safari": 10,
"ie": 11
},
"modules": false,
"useBuiltIns": true,
"debug": true
}]
],
}
λλ²κ·Έ νλκ·Έλ₯Ό νμ±ννμ¬ μμν λ λ€μ λ‘κ·Έλ₯Ό μ»μ΅λλ€. μ΄λ polyfillμ΄ μΆκ°λμμμ μλ―Ένλ κ² κ°μ΅λλ€.
babel-preset-env: `DEBUG` option
Using targets:
{
"safari": "10",
"ie": "11"
}
Modules transform: false
Using plugins:
check-es2015-constants {"ie":"11"}
transform-es2015-arrow-functions {"ie":"11"}
transform-es2015-block-scoping {"ie":"11"}
transform-es2015-classes {"ie":"11"}
transform-es2015-computed-properties {"ie":"11"}
transform-es2015-destructuring {"ie":"11"}
transform-es2015-duplicate-keys {"ie":"11"}
transform-es2015-for-of {"ie":"11"}
transform-es2015-function-name {"ie":"11"}
transform-es2015-literals {"ie":"11"}
transform-es2015-object-super {"ie":"11"}
transform-es2015-parameters {"ie":"11"}
transform-es2015-shorthand-properties {"ie":"11"}
transform-es2015-spread {"ie":"11"}
transform-es2015-sticky-regex {"ie":"11"}
transform-es2015-template-literals {"ie":"11"}
transform-es2015-typeof-symbol {"ie":"11"}
transform-es2015-unicode-regex {"ie":"11"}
transform-regenerator {"ie":"11"}
transform-exponentiation-operator {"safari":"10","ie":"11"}
transform-async-to-generator {"safari":"10","ie":"11"}
syntax-trailing-function-commas {"ie":"11"}
Using polyfills:
es6.typed.array-buffer {"ie":"11"}
es6.typed.int8-array {"ie":"11"}
es6.typed.uint8-array {"ie":"11"}
es6.typed.uint8-clamped-array {"ie":"11"}
es6.typed.int16-array {"ie":"11"}
es6.typed.uint16-array {"ie":"11"}
es6.typed.int32-array {"ie":"11"}
es6.typed.uint32-array {"ie":"11"}
es6.typed.float32-array {"ie":"11"}
es6.typed.float64-array {"ie":"11"}
es6.map {"ie":"11"}
es6.set {"ie":"11"}
es6.weak-map {"ie":"11"}
es6.weak-set {"ie":"11"}
es6.reflect.apply {"ie":"11"}
es6.reflect.construct {"ie":"11"}
es6.reflect.define-property {"ie":"11"}
es6.reflect.delete-property {"ie":"11"}
es6.reflect.get {"ie":"11"}
es6.reflect.get-own-property-descriptor {"ie":"11"}
es6.reflect.get-prototype-of {"ie":"11"}
es6.reflect.has {"ie":"11"}
es6.reflect.is-extensible {"ie":"11"}
es6.reflect.own-keys {"ie":"11"}
es6.reflect.prevent-extensions {"ie":"11"}
es6.reflect.set {"ie":"11"}
es6.reflect.set-prototype-of {"ie":"11"}
es6.promise {"ie":"11"}
es6.symbol {"ie":"11"}
es6.object.assign {"ie":"11"}
es6.object.is {"ie":"11"}
es6.function.name {"ie":"11"}
es6.string.raw {"ie":"11"}
es6.string.from-code-point {"ie":"11"}
es6.string.code-point-at {"ie":"11"}
es6.string.repeat {"ie":"11"}
es6.string.starts-with {"ie":"11"}
es6.string.ends-with {"ie":"11"}
es6.string.includes {"ie":"11"}
es6.regexp.flags {"ie":"11"}
es6.regexp.match {"ie":"11"}
es6.regexp.replace {"ie":"11"}
es6.regexp.split {"ie":"11"}
es6.regexp.search {"ie":"11"}
es6.array.from {"ie":"11"}
es6.array.of {"ie":"11"}
es6.array.copy-within {"ie":"11"}
es6.array.find {"ie":"11"}
es6.array.find-index {"ie":"11"}
es6.array.fill {"ie":"11"}
es6.array.iterator {"ie":"11"}
es6.number.is-finite {"ie":"11"}
es6.number.is-integer {"ie":"11"}
es6.number.is-safe-integer {"ie":"11"}
es6.number.is-nan {"ie":"11"}
es6.number.epsilon {"ie":"11"}
es6.number.min-safe-integer {"ie":"11"}
es6.number.max-safe-integer {"ie":"11"}
es6.math.acosh {"ie":"11"}
es6.math.asinh {"ie":"11"}
es6.math.atanh {"ie":"11"}
es6.math.cbrt {"ie":"11"}
es6.math.clz32 {"ie":"11"}
es6.math.cosh {"ie":"11"}
es6.math.expm1 {"ie":"11"}
es6.math.fround {"ie":"11"}
es6.math.hypot {"ie":"11"}
es6.math.imul {"ie":"11"}
es6.math.log1p {"ie":"11"}
es6.math.log10 {"ie":"11"}
es6.math.log2 {"ie":"11"}
es6.math.sign {"ie":"11"}
es6.math.sinh {"ie":"11"}
es6.math.tanh {"ie":"11"}
es6.math.trunc {"ie":"11"}
es7.array.includes {"ie":"11"}
es7.object.values {"safari":"10","ie":"11"}
es7.object.entries {"safari":"10","ie":"11"}
es7.object.get-own-property-descriptors {"safari":"10","ie":"11"}
es7.string.pad-start {"ie":"11"}
es7.string.pad-end {"ie":"11"}
web.timers {"safari":"10","ie":"11"}
web.immediate {"safari":"10","ie":"11"}
web.dom.iterable {"safari":"10","ie":"11"}
κ·Έλ¬λ λ°νμμ λ°°μ΄μμ .find () λ©μλλ₯Ό νΈμΆ ν λ IE11μμ μ¬μ ν μ€λ₯κ° λ°μν©λλ€.
ν΄λ¦¬ νμ΄ μ¬λ°λ₯΄κ² μ£Όμ λμλμ§ λ€μ νμΈνκΈ° μν΄ ν μμλ μΌμ΄ μμ΅λκΉ?
μν νλ‘μ νΈ @ https://github.com/jonaswindey/next-polyfill-bug
λ΄κ° κ°μ§ μ μΌν μμ μ¬νμ μ¬μ©μ μ μ layout.jsλ₯Ό μΆκ°νκ³
<script src='https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js' />
@arunoda μ°λ¦¬λ μ΄κ²μ μ μ λ³Έ μ μ΄ μμ΅λλ€ π€
ν«ν½μ€λ‘ λ€μμ μν ν μ μμ΅λλ€.
import 'core-js/fn/array/find'
const test = ['hi', 'there'].find(item => item === 'hi')
export default () => (
<div>{test}, welcome to next.js!</div>
)
μ¬κΈ°μ λ¬΄μ¨ μΌμ΄ μΌμ΄λλμ§ λ³΄μ.
μΌλ° λ°λ²¨ μ±μΌλ‘ νμΈνλλ° λμμ κ°μ΅λλ€.
μμμ μΈκΈ νλλ‘ polyfillμ μΆκ°ν΄μΌν©λλ€.
κ·Έλμ λλ μ΄κ²μ΄ μ νν λ€μ νΉμ λ¬Έμ κ° μλκΈ° λλ¬Έμ μ΄κ²μ λ«μ΅λλ€.
κ·Έλ¬λ λλ λ λ§μ μ μμ μ½λ λ€.
λ€μ μ΄μ΄ μ£ΌμκΈ° λ°λλλ€.
@arunoda λͺ¨λ νμΌμ λν΄ μμ νκΈ° μν΄ _document.js λ΄λΆμμ import 'core-js/fn/array/find'
λ‘μ΄ ν«ν½μ€λ₯Ό μλνμ§λ§ IE11μμλ μλνμ§ μμμ΅λλ€.
λ€μκ³Ό κ°μ΄ ν¬ν¨νκΈ° μν΄ μ루μ
μ μ¬μ©ν΄μΌνμ΅λλ€.
<script src='https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js' />
Next.js V3.0.6μ μ¬μ©νκ³ μμ΅λλ€.
μ΄ λ¬Έμ λ₯Ό λ μ’μ λ°©λ²μΌλ‘ ν΄κ²°ν μμλ λ°©λ²μ΄ μμ΅λκΉ?
λͺ¨λ μλ
.
next.config.js
μ entry-propertyλ₯Ό μ€ννμ΅λλ€.
μ΄κ²μ λ΄κ° κ°μ§ κ²μ
λλ€
(https://github.com/zeit/next.js/blob/master/server/build/webpack.js#L42μ λ°λ¦) :
module.exports = {
// eslint-disable-next-line no-unused-vars
webpack(config, _) {
const entry = async () => {
const resolvedEntry = await config.entry()
const entryWithPolyfill = Object.assign(
{ 'babel-polyfill': ['babel-polyfill'] },
resolvedEntry
)
// console.log(entryWithPolyfill)
return entryWithPolyfill
}
return Object.assign(
config,
entryWithPolyfill
)
}
}
μνκΉκ²λμ΄ νμΌμ babelμ μν΄ νΈλμ€ νμΌ λμ§ μμΌλ―λ‘ μμ§ μλνμ§ μμ΅λλ€ .
Nextμ μΉν© ꡬμ±μ babel-polyfill
μ ν¬ν¨νλ κ²μ΄ κ°μ₯ μ’μ΅λλ€. κ·Έκ²μ ν¬ν¨νλ κ²μ λ§€μ° μΌλ°μ μ
λλ€.
@arunoda μ΄λ»κ² μκ°νμΈμ?
μ΄κ²μ λν μ λ°μ΄νΈκ° μμ΅λκΉ? polyfillμ ν¬ν¨νλ κ²μ μ΅μ μ ν΄κ²°μ± μ΄ μλλλ€
μ΄κ²λ κ΄μ¬μ΄ π€
μ΄ λ°λ²¨ ν΄λ¦¬ ν κ°μ Έ μ€κΈ°λ₯Ό μμ νμ΅λλ€.
import 'babel-polyfill';
babel-polyfill
μ 체λ₯Ό κ°μ Έ μ€λ κ²μ λ§€μ° λλΉ μ μ΄λ©° next.js, imhoμ λν μλͺ»λ κΈ°λ³Έκ°μ
λλ€. μ€μ λ‘ ν΄λ¦¬ ν κΈ°λ₯μ΄ νμνμ§ μ¬λΆμ κ΄κ³μμ΄ λ²λ€μ 87kbλ₯Ό μΆκ°ν©λλ€.
@sholzmayer import 'babel-polyfill';
μ΄λμ μ¬μ© νμ΅λκΉ? _document.jsμμ μλνμ§λ§ λμμ΄λμ§ μμμ΅λλ€.
@klaemo κ·Έλμ λΉμ μ μ μμ 무μμ λκΉ?
transform-runtime
μ .babelrc
νλ¬κ·ΈμΈμ μΆκ°νλ©΄ λμκ² λμμ΄λλ κ² κ°μ΅λλ€. Object.entriesκ° λ΄μ₯λμ§ μμ Opera 36 μ© μ±μ κ°λ° μ€μ
λλ€.
"plugins": [
"transform-runtime"
]
@hugotox λ μ± κ°λ°μλ‘μ https://polyfill.io λ₯Ό μ¬μ©νμ¬ νμν ν΄λ¦¬ ν λ§λ‘λνκ±°λ μλμΌλ‘ μν ν μ μμ΅λλ€. μ°λ¦¬ μ±μλ λ€μκ³Ό κ°μ polyfills.js
μ΄ μμ΅λλ€.
// Language features presented by https://github.com/zloirock/core-js
import 'core-js/fn/object/assign'
import 'core-js/fn/string/ends-with'
import 'core-js/fn/string/starts-with'
import 'core-js/fn/string/includes'
import 'core-js/fn/array/includes'
import 'core-js/fn/weak-map'
// browser features
import 'raf/polyfill'
import 'isomorphic-fetch'
import 'js-polyfills/url'
λλ nextjsλ core-js
μμ νμν λͺ¨λ polyfillμ κ°μ Έμ λ²λ€λ‘ μ 곡 ν μ μμ΅λλ€.
@igimanaloto μ΄ μ루μ μ΄ μ μκ²
λλ λν transform-runtime
νλ¬κ·ΈμΈμ μ¬μ©νμ§λ§ μ΄λ€ μ΄μ λ‘ IEμμ μ€λ₯κ° λ°μν©λλ€.
{
"plugins": [
"source-map-support",
"transform-runtime"
],
"presets": [
["env", {
"targets": {
"node": "6.10"
}
}],
["stage-3"],
[
"next/babel",
{
"styled-jsx": {
"optimizeForSpeed": true,
"vendorPrefixes": true,
"sourceMaps": true,
"plugins": [
"styled-jsx-plugin-sass"
]
}
}
]
]
}
@bliitzkrieg μμ£Ό κ°μ Έμ¬ μ μμ΅λλ€ babel-polyfill
μμ _document.js
, λλ¬Έμ _document.js
μλ²μμλ§ λ λλ§λ©λλ€.
μΌλ°μ μΌλ‘ λ μ΄μμμ ν¬ν¨νλ κ²μ΄ μ’μ΅λλ€. κΈ°λ³Έμ μΌλ‘ λͺ¨λ νμ΄μ§μμλ‘λλλ λͺ¨λ νμΌμ΄ μ μμ μΌλ‘ μλν©λλ€.
μ
λ°μ΄νΈ : IE 10, 11 core-js/library/fn/object/assign
μ μμ‘΄ client/polyfill.js
λ‘ core-js/fn/object/assign
(@klaemo μλ μ΄λ»κ² κ·Έκ²μ-λ§μμ΅λλ€!)
μ¬κΈ°κ° Dockerized κ² next 5.1.0
μ κ·Ό λ°©μμ μ‘°ν©μ μμ @klaemo λ° κ³΅μ μμ μν΄ νμ μ¬μ©μ μλ, μΉ΄λ리μ / μ /μ-polyfills :
[μλ μ§λ¬Έ] IE11μ κ°μ Έ μ€λ client / polyfills.js νμΌμμ core-js
μ μ¬μ©λ²μ 무μμ
λκΉ? (λλ IE11μ΄ λλ½ λ λͺ¨λ κ²μ ν¬ν¨νλ κ°μ Έ μ€κΈ°μμ μ κ·Όμ μ§ν ν λ€μ μ μ°¨μ μΌλ‘ μ±μ νμν νλͺ©μΌλ‘ λ²μλ₯Ό μΆμ ν κ²μΌλ‘ μμ ν μ μμ΅λλ€.)
λ€μμ λͺ κ°μ§ OS + λΈλΌμ°μ μ‘°ν© (λΈλΌμ°μ μ€ν) μμ κ²°κ³Ό λ₯Ό μ΄λ©° Windows 10 + IE11 (μλ μ°Έμ‘°) λ° κΈ°ν IE μ‘°ν©μμ μ€ν¨ν©λλ€ .
μ¬μ©μ μ μ μλ², .babelrc λ° webpack ꡬμ±μ μ¬μ©νμ¬ ν¬λ‘¬ 43μμ next 5.1.0
μ (λ₯Ό) μ€ννλ €κ³ νμ΅λλ€. import 'core-js/fn/object/assign';
μ΄ (κ°) νΈλ¦μνμ΅λλ€.
μ΄ λ²κ·Έκ° μ¬μ ν μ‘΄μ¬νλ κ² κ°μ΅λλ€! IE 11μμ λμΌν λ¬Έμ μ μ§λ©΄νκ³ μμΌλ©° μ΄λ€ μ루μ λ λμμ΄λμ§ μμ΅λλ€. λ¬Έμ λ νμ΄ν κΈ°λ₯μ μ¬μ©νλ ansi-regex ν¨ν€μ§λ‘ 보μ΄λ©° μ΄κ²μ next.jsμ μ’ μμ±μ λλ€.
@arunoda @timneutkens μ΄ λ¬Έμ λ₯Ό λ€μ μ΄ μ μμ΅λκΉ?
μλ μ¬μ ν μ‘΄μ¬ν©λλ€. μμ¬ ν΄μλλ₯Ό μ¬μ©νμ¬ λ€μ΄ κ·Έλ μ΄λ
import 'core-js/fn/object/assign'
μ μκ² ν¨κ³Όμ μ΄μμ΅λλ€.
core-js
λ¨Όμ μΆκ°ν΄μΌνμ΅λλ€ ( yarn add core-js
)-λ¬Όλ‘ μ
λλ€.
λλ μ΄κ²μ΄ λμμ΄λλ€λ κ²μ μμλ€ : https://github.com/aspnet/JavaScriptServices/wiki/Supporting-Internet-Explorer-11- (λλ -older)
λ Έλ λͺ¨λ μ© ES6 νΈλμ€ νμΌμ λν 곡μ λ¬Έμλ₯Ό μΆκ°νμΈμ.
μ¬κΈ°μ ν΄κ²° λ°©λ²μ΄ μμ§λ§μ΄ λ²κ·Έλ λ€μ μ΄μ΄μΌν©λλ€. μ루
ie11μμ Object.assign, String.endsWith μ€λ₯κ° λ°μνμ΅λλ€ ([email protected])
const {basedir} = require ( './ server / config');
// μλ²κ·Έλ¦°μ΄ μλ λΈλΌμ°μ μ νμν ν΄λ¦¬ ν (μ£Όλ‘ μ¦)
const polyfills = [
'core-js / fn / object / assign',
'core-js / fn / string / ends-with',
'core-js / fn / string / starts-with',
'core-js / fn / string / includes',
'core-js / fn / array / includes',
'core-js / fn / weak-map',
];
module.exports = {
webpack: (config, {dev, isServer}) => {
const originalEntry = config.entry;
if (!isServer) {
config.entry = async () => {
const entries = await originalEntry();
Object.values(entries).forEach(entry => {
entry.unshift(...polyfills);
if (dev) {
entry.unshift('eventsource-polyfill');
}
});
return entries;
};
}
return config;
},
};
μ€μ λ‘ λλ λλλ‘ μ»λλ€
Cannot redefine non-configurable property 'endsWith'
μ΄ μμ λ₯Ό λ°λΌ polyfillμ ν¬ν¨νμ΅λλ€.
IE11μ΄ μλνλ €λ©΄ client/polyfills.js
λ€μμ ν¬ν¨ν΄μΌνμ΅λλ€.
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/fn/object/assign';
import 'core-js/fn/string/ends-with';
import 'core-js/fn/string/starts-with';
import 'core-js/fn/string/includes';
import 'core-js/fn/array/includes';
import 'core-js/fn/array/find';
import 'core-js/fn/number/is-finite';
μλ₯Ό λ€μ΄ isFiniteκ° νμν λΌμ΄λΈλ¬λ¦¬κ°μμ λλ§λ€ νμ€νμ§ μμ§λ§ λ΄ μ±μ λ§€μ° μ μ΅λλ€.
μ΄κ²μ μλνμ§λ§ μ€μ λ‘ νμν ν΄λ¦¬ νμ νμ νλ κ²μ λ§€μ° λ²κ±° λ‘μ΅λλ€.
λꡬλ μ§ IE11μμ μλνλ ν΄λμ€ κ΅¬λ¬Έμ μ»κΈ° μν΄ μ΄λ€ polyfillμ΄ νμνμ§ μκ³ μμ΅λκΉ?
ν΄λμ€ Foo νμ₯ ...
λΉμ μ polyfillsμμ 'import'core-js / es6 / object ';' μ
λλ λΉμ μ΄ @peec μ μΈκΈ ν μλ₯Ό
@peec μ΄ μμλλ λμμ λκΉ? ν¬ν¨ λ νλͺ©μ λ€μ ν΄λ¦¬ νν΄μΌνλ μ΄μ λ 무μμ λκΉ?
κ°μ₯ μ μ©ν λκΈ
λ΄κ° κ°μ§ μ μΌν μμ μ¬νμ μ¬μ©μ μ μ layout.jsλ₯Ό μΆκ°νκ³
<script src='https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js' />