taylorstine
taylorstine

Reputation: 925

Babel 6: Too many arguments passed error

When I try running my server that uses babel 6, I get the following error:

Error: /path/to/myapp/server.js: t.Identifier: Too many arguments passed. Received 3 but can receive no more than 1

Here's what my package.json looks like:

{
  "scripts": {
  "start": "node app.js",
  "postinstall": "bash ./scripts/npm-post.sh",
  "test": "mocha test"
},
  "dependencies": {
    "babel": "^6.0.15",
    "babel-core": "^6.0.20",
    "babel-preset-react": "^6.0.15",
    "babel-preset-stage-0": "^6.0.15",
    "react": "^0.14.2",
    "react-dom": "^0.14.2",
    "react-helmet": "^2.1.1",
    "react-router": "^1.0.0-rc3",
    "reactify": "^1.1.1",
  },
  "devDependencies": {
    "babel-preset-es2015": "^6.0.15",
  }
}

Here's my app.js

require('babel-core/register')({
  "presets": [
    "es2015",
    'react'
  ]
});
require('./server.js')

And server.js

console.log('hi')

hi is not printed to the console.

Upvotes: 3

Views: 305

Answers (2)

Nick Wargnier
Nick Wargnier

Reputation: 1461

I fixed this by uninstalling the babel-preset-react plugin and then reininstalling so it installed the latest dependency. If that doens't work you may need to rm -rf node_modules and remove your shrinkwrap if you have one then rerun npm install

Upvotes: 3

taylorstine
taylorstine

Reputation: 925

I've solved the issue, it appears to be a bug in the v6.0.14 version of babel-plugin-transform-react-jsx, here: https://github.com/babel/babel/blob/v6.0.14/packages/babel-plugin-transform-react-jsx/src/index.js#L36

the v6.0.14 version of the plugin is required by the latest version of the babel react preset https://github.com/babel/babel/blob/master/packages/babel-preset-react/package.json#L13

The latest version (v6.0.18) of babel-plugin-transform-react-jsx fixes the issue. https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-react-jsx/src/index.js#L36

So when I used the react preset, I got the above error.

To fix it, I changed my babel configuration to the following (note that I switched to using a .babelrc instead of an inline configuration in app.js, but the result should be the same.

.babelrc was:

{
  "presets": ["es2015", "react"]
}

.babelrc is now:

{
  "presets": ["es2015"],
  "plugins": ["transform-react-jsx"]
}

package.json now has the added dependency

"babel-plugin-transform-react-jsx": "^6.0.18",

Upvotes: 4

Related Questions