Los módulos Babel 6.0.20 no funcionan en IE8
Estoy tratando de exportar un módulo es6 en header.js
:
export default {
setHeaderHighlight: function (index) {
// do somethings
}
};
E importarlo en index.js
:
import header from "./header.js"
$(function () {
header.setHeaderHighlight(0);
});
Entonces la transformación sale en index.bundle.js
:
var _header = __webpack_require__(129);
var _header2 = _interopRequireDefault(_header);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj }; // crash here
}
Así que aquí está el problema, ie8 se levantará una Excepción Expected identifier
en { default: obj }
, pero todo está bien >=ie9.
¿Hay algo que pueda hacer con esto?
3 answers
Por defecto, Babel 6.x requiere que habilite un conjunto explícito de transformaciones. El preset estándar es2015
convierte ES6 a ES5, sin embargo IE8 no es compatible con ES5. En este caso, si nos fijamos en la lista plugins , verá
Estos convertirán sus propiedades para ser compatibles con IE8. Generalmente en Babel 6.x usted haría esto pasando esos nombres como parte de su matriz plugins
, junto con la matriz presets
e instalar las transformaciones a través de
npm install --save-dev babel-plugin-transform-es3-member-expression-literals babel-plugin-transform-es3-property-literals
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-04 17:08:58
Uso webpack + es3ify-loader como solución alternativa.
loaders: {
{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['es3ify', `babel?${JSON.stringify(babelQuery)}`],
},
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-18 06:23:49
También tengo el problema, y escribí un plugin webpack para resolverlo. Realmente no sabía si había una mejor manera de manejarlo, pero funciona.
El módulo en node_modules también funciona bien.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-01 06:04:31