2015-11-03 39 views
3

巴貝爾6:參數太多,當我嘗試運行我的服務器,它使用巴貝爾6,我收到以下錯誤傳遞錯誤

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

這裏是我的package.json是什麼樣子:

{ 
    "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", 
    } 
} 

這是我的app.js

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

server.js

console.log('hi') 

hi未打印到控制檯。

回答

4

我已經解決了這個問題,這似乎是在babel-plugin-transform-react-jsx的v6.0.14版中的錯誤,在這裏: https://github.com/babel/babel/blob/v6.0.14/packages/babel-plugin-transform-react-jsx/src/index.js#L36

插件的v6.0.14版本由的最新版本所需巴貝爾反應預設 https://github.com/babel/babel/blob/master/packages/babel-preset-react/package.json#L13

babel-plugin-transform-react-jsx的最新版本(v6.0.18)解決了這個問題。 https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-react-jsx/src/index.js#L36

所以當我用react預設的,我得到了上述錯誤。

要解決它,我改變了我的巴貝爾配置如下(請注意,我切換到使用.babelrc代替app.js直列配置的,但結果應該是一樣的

.babelrc是:

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

.babelrc現在是:

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

package.json現在有添加依賴

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

我通過卸載插件babel-preset-react,然後reininstalling所以它安裝了最新的依賴固定這一點。如果這不起作用,您可能需要rm -rf node_modules並刪除您的shrinkwrap如果您有一個然後重新運行npm install