2016-02-29 35 views
1

一旦運行react-native init testNative反應本土的init:的ReferenceError:BABEL]未知選項:未知選項:base.optional

ReferenceError: [BABEL] /Users/m/git/testNative/node_modules/react-native/local-cli/bundle/bundle.js: Unknown option: base.optional 
    at Logger.error (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/logger.js:41:11) 
    at OptionManager.mergeOptions (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/options/option-manager.js:289:18) 
    at OptionManager.init (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/options/option-manager.js:486:10) 
    at File.initOptions (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/index.js:211:75) 
    at new File (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/index.js:129:22) 
    at Pipeline.transform (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/pipeline.js:48:16) 
    at Object.transformFileSync (/Users/m/git/testNative/node_modules/babel-core/lib/api/node.js:118:10) 
    at compile (/Users/m/git/testNative/node_modules/babel-register/lib/node.js:100:20) 
    at loader (/Users/m/git/testNative/node_modules/babel-register/lib/node.js:128:14) 
    at Object.require.extensions.(anonymous function) [as .js] (/Users/m/git/testNative/node_modules/babel-register/lib/node.js:138:7) 

我試過在以下職位的建議,我發現了以下錯誤(https://github.com/facebook/react-native/issues/5https://github.com/babel/babel-loader/issues/132,https://github.com/babel/babelify/issues/129,React 0.14 error: Module build failed: ReferenceError: [BABEL] .../node_modules/eslint-loader/index.js!/.../main.jsx: Unknown option: base.stage),但無濟於事。

我目前的假設是因爲我的系統上沒有任何地方的.babelrc文件,所以它會回落到「base.optional」。至少將一個.babelrc文件添加到我的項目文件夾是唯一產生不同結果的東西(降級節點,babel或react-native什麼也不做)。所以,如果這是解決方案,有沒有人知道我的.babelrc文件應該包括一個react-native項目?

感謝

回答

1

這裏是.babelrc文件,您可以與您的RN項目中使用的一個。 注意在RN工作正常,沒有.babelrc文件在您的項目(它退到node_modules/react-native/.babelrc文件

{ 
    "retainLines": true, 
    "compact": true, 
    "comments": false, 
    "plugins": [], 
    "presets": ["stage-0", "react", "react-native"], 
    "sourceMaps": false, 
} 

您還需要將這些行添加到您package.json文件並安裝DEV-依賴關係:npm i --save-dev <package-name>

"devDependencies": { 
    "babel-preset-react": "^6.3.13", 
    "babel-preset-react-native": "^1.4.0", 
    "babel-preset-stage-0": "^6.3.13" 
} 
+0

非常感謝你,這就像一個魅力! – jaxoncreed