El archivo Babel se copia sin ser transformado
Tengo este código:
"use strict";
import browserSync from "browser-sync";
import httpProxy from "http-proxy";
let proxy = httpProxy.createProxyServer({});
Y he instalado babel-core
y babel-cli
globalmente a través de npm. El punto es cuando intento compilar con esto en mi terminal:
babel proxy.js --out-file proxified.js
El archivo de salida se copia en lugar de compilarse (es decir, es el mismo que el archivo de origen).
¿Qué me estoy perdiendo aquí?
7 answers
Babel es un framework de transformación. Pre-6.x, habilitó ciertas transformaciones de forma predeterminada, pero con el mayor uso de las versiones de nodo que admiten de forma nativa muchas características de ES6, se ha vuelto mucho más importante que las cosas sean configurables. Por defecto, Babel 6.x no realiza ninguna transformación. Necesitas decirle qué transformaciones ejecutar:
npm install babel-preset-env
Y corre
babel --presets env proxy.js --out-file proxified.js
O crear un archivo .babelrc
que contenga
{
"presets": [
"env"
]
}
Y ejecutarlo tal como lo fueron antes.
env
en este caso es un preset que básicamente dice compilar todo el comportamiento estándar ES * a ES5. Si está utilizando versiones de nodo que admiten algunos ES6, es posible que desee considerar hacer
{
"presets": [
["env", { "targets": { "node": "true" } }],
]
}
Para decirle al preset que solo procese cosas que no son compatibles con su versión de nodo. También puede incluir versiones del navegador en sus destinos si necesita compatibilidad con el navegador.
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
2018-04-30 02:44:05
Tuve el mismo problema con una causa diferente:
El código que estaba intentando cargar no estaba en el directorio del paquete, y Babel no transpira por defecto fuera del directorio del paquete.
Lo resolví moviendo el código importado, pero quizás también podría haber usado alguna instrucción de inclusión en la configuración de Babel.
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-10 04:18:48
Primero asegúrese de tener lo siguiente node modules
:
npm i -D webpack babel-core babel-preset-es2015 babel-preset-stage-2 babel-loader
A continuación, agregue esto a su archivo de configuración de Webpack (webpack.config.js
) :
// webpack.config.js
...
module : {
loaders : [
{
test : /\.js$/,
loader : 'babel',
exclude : /node_modules/,
options : {
presets : [ 'es2015', 'stage-2' ] // stage-2 if required
}
}
]
}
...
Referencias:
¡Buena Suerte!
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
2017-07-27 01:07:20
npm install --save-dev babel-preset-node5
npm install --save-dev babel-preset-react
...y luego crear un .babelrc
con los presets:
{
"presets": [
"node5",
"react"
]
}
...se resolvió un problema muy similar para mí, con babel 3.8.6
, y node v5.10.1
Https://www.npmjs.com/package/babel-preset-node5
https://www.npmjs.com/package/babel-preset-react
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-04-19 00:56:31
Mismo error, causa diferente:
Transpiling había funcionado antes y luego de repente dejó de funcionar, con los archivos simplemente se copian como están.
Resulta que abrí el .babelrc
en algún momento y Windows decidió agregar .txt
al nombre del archivo. Ahora que .babelrc.txt
no fue reconocido por babel. La eliminación del sufijo .txt
solucionó eso.
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
2017-07-11 07:57:49
Arreglar su .babelrc
{
"presets": [
"react",
"ES2015"
]
}
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
2018-02-26 19:22:53
En el año 2018:
Instale los siguientes paquetes si aún no lo ha hecho:
npm install babel-loader babel-preset-react
Webpack.config.js
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['es2015','react'] // <--- !`react` must be part of presets!
}
}
],
}
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
2018-08-10 13:02:32