Thursday 20 April 2017

ES6 style imports in Node.js REPL

Coming from a Python background and being new to Node.js, I've found it surprisingly difficult to interactively try code with Node.js REPL. One key problem that I have faced is with imports:

ES6 style imports won't work on the Node.js REPL and I have to use CommonJS style imports using require. Example: I can't write import rxjs at the Node prompt and have to use require('rxjs'). This makes it harder to copy paste scripts into Node REPL to quickly test them and I have to first convert all ES6 style imports to require imports which feels counterintuitive.

Is there any simple way to be able to use ES6 style imports from the Node.js REPL ?

Like:

$ node
> import 'rxjs';
> import {map} from 'rxjs/operator/map';

I even tried babel-node which doesn't seem to support module imports either.



via Pranjal Mittal

No comments:

Post a Comment