babel: Error in babel-register 6.16.0

After updating to babel register 6.16.0 I started getting the following error.

/myproject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:319
        throw e;
        ^
SyntaxError:  (While processing preset: "/myproject/node_modules/babel-preset-es2015/lib/index.js")

.babelrc

{
  "presets": [
    ["es2015", { "modules": false }],
    "stage-1",
    "react"
  ],
  "plugins": [
    "transform-runtime"
  ],
  "env": {
    "development": {
      "plugins": ["react-hot-loader/babel", "transform-runtime"]
    },
    "test": {
      "presets": ["es2015", "stage-1", "react"],
    }
  },
  "compact": true
}

package.json

{
  "dependencies": {
    ...
    "babel-core": "^6.3.26",
    "babel-loader": "^6.2.0",
    "babel-plugin-transform-runtime": "^6.12.0",
    "babel-polyfill": "^6.9.0",
    "babel-preset-es2015": "^6.13.0",
    "babel-preset-react": "^6.11.0",
    "babel-preset-stage-1": "^6.13.0",
    "babel-register": "^6.8.0",
    "babel-runtime": "^6.11.6",
    ...
  }
}

After resetting babel-register to 6.14.0 the error went away.

I’m thinking it might have something to do with this commit https://github.com/babel/babel/commit/71dff8c834191356bfc58d24f37e3601df96987e

software version
Babel 6.16.0
node 6.6.0
npm 3.10.3
Operating System OS X 10.11.6 (15G1004)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 13
  • Comments: 24 (10 by maintainers)

Commits related to this issue

Most upvoted comments

We also started seeing a strange error:

node_modules/sinon/lib/sinon/util/core.js:153
            method.stackTrace = (new Error("Stack Trace for original")).stack;
                                                                       ^
NetworkError:

The release of babel 6.16.0 triggered this, and explicitly adding babel-register 6.14 to our package.json alleviates the issue.

Edit: We ended up having to pin both babel-core and babel-register to 6.14.0.

@danez Ok, so my investigation is complete 😃

In the enzyme solution, they suggest doing the following for every property of jsdom('').defaultView:

global[property] = document.defaultView[property];

One of the properties overloaded is XMLHttpRequest.

Adding the following solves the issue.

    delete global['XMLHttpRequest'];

Can you please check why having a global.XMLHttpRequest screws up babel?

FYI - Updated my example to be even more minimal. See initJsdom in the spec/setup.js

@danez , @3LOK ,

It may be this snippet, which is recommended by the folks who make the enzyme library, https://github.com/airbnb/enzyme/blob/master/docs/guides/jsdom.md

    /* setup.js */

    var jsdom = require('jsdom').jsdom;

    global.document = jsdom('');
    global.window = document.defaultView;
    Object.keys(document.defaultView).forEach((property) => {
      if (typeof global[property] === 'undefined') {
        global[property] = document.defaultView[property];
      }
    });

    global.navigator = {
      userAgent: 'node.js'
    };

I have added a call at the top of that:

    require('babel-register')();

Could that combination be causing the error in the new version?

@danez ,

I only see the error when I upgrade both babel-core and babel-register, and when I try to run Mocha tests, because I only use babel-register in my test setup helper, not my build process. (I use Webpack’s babel-loader in the build.)

Here’s the error I was getting:

    $ npm t

    > project-name@1.0.0 test /Users/vwilson/Projects/ex3-mocha-enzyme
    > mocha --reporter spec test/helpers/testSetup.js "test/**/*.test.js"


    /Users/vwilson/Projects/ex3-mocha-enzyme/node_modules/babel-core/lib/transformation/file/options/option-manager.js:319
            throw e;
            ^
    SyntaxError:  (While processing preset: "/Users/vwilson/Projects/ex3-mocha-enzyme/node_modules/babel-preset-es2015/lib/index.js")
    npm ERR! Test failed.  See above for more details.

I downgraded just babe-register, which seems to fix it, but I then downgraded babel-core, too, just to be safe.