video recorder를 만드는 과정에서 에러가 발생했다.
Uncaught ReferenceError: regeneratorRuntime is not defined
Babel이 변환하지 못하는 새로 추가된 object(Promise, Map, Set...)나 method(String.padStart...)가 있어서 발생함.
모든 polyfill을 받아서 문제를 해결하는 방법이다.
polyfill이 필요한 경우, Babel 내부 helper 함수를 사용하도록 바꿔주는 plugin이다.
// webpack
include: [
/src\/js/,
/node_modules\/axios/
],
기본적으로 Babel은 사용자 정의 regenerator runtime 과 core-js를 포함하는 polyfill을 가지고 있다. 이들을 정의하고 babel-node를 사용해주면 자동적으로 load된다. core-js를 정의해주자.
// webpack
presets: [
[
"@babel/preset-env",
{
corejs: 3,
useBuiltIns: "usage",
shippedProposals: true,
},
],
],
필자는 webpack을 통해 js를 변환하므로 이렇게 했지만, babel.config.js에 corejs를 정의해도 된다.
@babel/preset-env이 어떻게 polyfill을 다룰지 정하는 option이다.
plugin-transform-runtime이 가지는 장점을 모두 가진다.plugin-transform-runtime의 단점 중 2번이 해결된다.@babel/polyfill
@babel/plugin-transform-runtime
@babel/polyfill & @babel/plugin-transform-runtime
core-js
core-js