alekseykulikov / babel-preset-es2015-node5 Goto Github PK
View Code? Open in Web Editor NEWBabel preset to make node@5 fully ES2015 compatible
License: MIT License
Babel preset to make node@5 fully ES2015 compatible
License: MIT License
Now that Node 6 is out, can this be extended to support it too?
I'm using this preset to transpile code that worked well with Babel 5. It breaks when Express tries to mount the routes, in a way that suggests the transpiled code does not sit well with the Express Router:
/Users/project/node_modules/express/lib/router/index.js:458
throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn));
^
TypeError: Router.use() requires middleware function but got a Object
at Function.use (/Users/project/node_modules/express/lib/router/index.js:458:13)
at EventEmitter.<anonymous> (/Users/project/node_modules/express/lib/application.js:219:21)
at Array.forEach (native)
at EventEmitter.use (/Users/project/node_modules/express/lib/application.js:216:7)
at Object.<anonymous> (/Users/project/lib/app.js:26:5)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
The line in the app.js
file referred to is:
app.use('/', routes);
And the routes
object is a file that uses Express.Router to mount some simple GET/POST routes. As said, same file worked great before I upgraded to Babel 6.
Update:
My routes
file looks (roughly) like this:
import express from 'express';
var router = express.Router();
router.get('/', (req, res) => {
//code
});
...
//more routes
...
export default router;
If I change the last line to module.exports = router;
everything works, so I think it may have something to do with transpiling export default
?
see jbach/babel-preset-es2015-node4#1 , same issue persists in Node 5
What is the correct config for using async/await with es2015-node5? I'm using babel 6 on node 5 and having trouble with async funcitons. Here is my code:
import { getId } from '../utils';
...
const userId = await getId(...);
The transpiled code is as follow:
var _utils = require('../utils');
...
const userId = yield (0, _utils.getId)(...);
.babelrc:
{
"presets": ["stage-0", "es2015-node5"]
}
.package.json:
"dependencies": {
"babel-polyfill": "^6.2.0",
"babel-preset-es2015-node5": "^1.1.0",
"babel-preset-stage-0": "^6.1.18",
...
It gives me error (0 , _utils.getId) is not a function
In my entry js file I already called import 'babel-polyfill';
. What am I missing to make it work?
While node5 does support shorthand properties, the following case fail in node and not in Chrome:
function get() {}
function set() {}
// This line fails.
const obj = { get, set };
I think we should include babel-plugin-transform-es2015-shorthand-properties
to remedy this until node ships with a version of v8 that has fixed this.
I write my webpack.config.js like this :
{test: /.js$/, loaders: ['react-hot', 'babel?presets[]=es2015'], exclude: /node_modules/}
I want and presets ['react'] into my config, How should I write my config file ?
I need your help . thank you !
The V8 in node 5 does not support ES2015 compatible block scoping for let and const.
For example, in node 5.2, this input:
const a = {a: 'b', c: 'd', e: 'f'}
for (const key in a) { console.log(key, a[key]); }
produces this output:
a b
a b
a b
Whereas according to the spec it should output:
a b
c d
e f
This is fixed by including babel-plugin-transform-es2015-block-scoping
in the preset.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.