XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

Boilerplate ... broken??? #703

Closed karma0 closed 8 years ago

karma0 commented 8 years ago

When attempting to get past the first step in walking through the API documentation using ripple-lib, I receive the following error when attempting babel-node boilerplate.js:

(function (exports, require, module, __filename, __dirname) { const { RippleAPI } = require('ripple-lib');
                                                                    ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at loader (/home/karma0/src/node/stegs/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/karma0/src/node/stegs/node_modules/babel-register/lib/node.js:136:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at /home/karma0/src/node/stegs/node_modules/babel-cli/lib/_babel-node.js:161:27
    at Object.<anonymous> (/home/karma0/src/node/stegs/node_modules/babel-cli/lib/_babel-node.js:162:7)
    at Module._compile (module.js:413:34)

It appears as though babel and/or node are clueless about how to handle this line:

const {RippleAPI} = require('ripple-lib');

But, then, maybe I'm missing something here.

Node version: v5.6.0 Babel version: 6.6.5 (babel-core 6.7.2)

jnr101 commented 8 years ago

You need to preset babel to es2015. check here for several methods to do this. For the above example you can use

babel-node --presets es2015 boilerplate.js

karma0 commented 8 years ago

Worked. Just needed to install the babel-preset-es2015 npm module, then it executed exactly as you suggested. Seems I need to do a bit of reading. Thanks!