Starting a new project and I'm wanting to use ES6/2015 features with Node. Currently trying use the babel-core require hook. This seems simple enough, but my required modules are throwing syntax errors.
App entry point:
require("babel-core/register")({
ignore: false
});
var app = require('app/app');
...
Required file (app/app.js):
// this SHOULD be compiled by the Babel require hook
app.get('/', (req, res, next) => res.render('page/page', {}));
Syntax Error:
app.get('/', (req, res, next) => res.render('page/page', {}));
^^
SyntaxError: Unexpected token =>
Babel-core: 6.1.21
I am sure I am missing something really simple. Any help would be greatly appreciated. Thanks!
Babel core needs a preset to transform something. If you want to use ES2015, this preset is called babel-preset-es2015.
Add this preset to your project : npm install --save-dev babel-preset-es2015
With babel 6 you also need to create a .babelrc file in your root folder.
Add es2015 to use babel-preset-es2015.
{
"presets": ["es2015"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With