Skip to content

Instantly share code, notes, and snippets.

@eventualbuddha
Created April 2, 2015 23:05
Show Gist options
  • Save eventualbuddha/c807401d3d206600392d to your computer and use it in GitHub Desktop.
Save eventualbuddha/c807401d3d206600392d to your computer and use it in GitHub Desktop.
// index.js
require('babel/register')({ only: /tests/ });
require('./tests');
// lib/index.js
console.log('' + this);
class Bar {
}
// tests/index.js
require('../lib');
class Foo {
}
@eventualbuddha
Copy link
Author

$ npm install babel
$ node index.js
lib/index.js:3
class Bar {
^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:393:25)
    at Module._extensions..js (module.js:428:10)
    at Object.require.extensions.(anonymous function) [as .js] (node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:133:7)
    at Module.load (module.js:335:32)
    at Function.Module._load (module.js:290:12)
    at Module.require (module.js:345:17)
    at require (module.js:364:17)
    at Object.<anonymous> (tests/index.js:1:1)
    at Module._compile (module.js:410:26)

This fails as expected because babel is not transpiling lib/index.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment