CLI · Babel


#1

Babel comes with a built-in CLI which can be used to compile files from the command line.

While you can install Babel CLI globally on your machine, it’s much better to install it locally project by project.


This is a companion discussion topic for the original entry at https://babeljs.io/docs/usage/cli/

#2

Hello Babel Team ! Could you teach me how to understand this sentence: “ES6-style module-loading may not function as expected”

?


#3

For example:

$ babel-node
> var uuid = require("uuid");
undefined
> uuid.v4();
'64f809c9-496a-4d17-a2d8-0a7d70501964'
> import v4 from "uuid";
SyntaxError: repl: Modules aren't supported in the REPL
> 1 | import v4 from "uuid";
    | ^
    at File.buildCodeFrameError (/home/user/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:431:15)
    at NodePath.buildCodeFrameError (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/index.js:140:26)
    at PluginPass.ModuleDeclaration (/home/user/lib/node_modules/babel-cli/lib/_babel-node.js:75:20)
    at newFn (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/home/user/lib/node_modules/babel-cli/node_modules/babel-traverse/lib/context.js:190:19)


#4

Not saying it would still work but wouldn’t the import syntax be:

import { v4 } from "uuid";

#5

@eudaimos yes, the correct ES6 syntax is import {v4} from "uuid"; .

I’ve just checked this syntax on babel-node and it fails with the same error message.


#6

Is there a way to specify preset options (like {"modules": false}) using babel-cli only ?
It means without using .babelrc


#7

image
node_modules.bin\babel script.js


#8

How do you use rlwrap? I can’t find it on npm.