Using Babel in my NodeJSv4.1.1 code.
Got the require hook in:
require(\"babel-core/register\");
$appRoot = __dirname;
module.exports = require(\".
Sounds like you aren't using the right presets. As of babel 6, the core babel loader no longer includes the expected ES6 transforms by default (it's now a generic code transformer platform), instead you must use a preset:
require('babel-register')({
"presets": ["es2015"]
});
You will also need to install the preset package:
npm install --save-dev babel-preset-es2015
It seems that this file is not being transpiled. Is this subsequently loaded .js
file in the node_modules directory? If so, you need to:
require("babel-core/register")({
// This will override `node_modules` ignoring - you can alternatively pass
// an array of strings to be explicitly matched or a regex / glob
ignore: false
});
By default all requires to node_modules will be ignored. You can override this by passing an ignore regex
https://babeljs.io/docs/usage/require/
I was hitting the problem when trying to run tests via mocha, and I solved it by putting this in my package.json file:
"babel": {
"presets": [
"es2015"
]
},
I'm not completely clear on how this works. I'm running tests like this:
mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive
Eventually, this will all make sense I suppose.