2016-01-13 39 views
0

我跑很簡單的代碼中使用反應 - 本機的tableview錯誤建築DependencyGraph:錯誤:命名碰撞檢測

'use strict'; 

var React = require('react-native'); 
var { AppRegistry } = React; 
var TableView = require('react-native-tableview'); 
var Section = TableView.Section; 
var Item = TableView.Item; 

class AwesomeProject extends React.Component { 
    render(){ 
     return (
      <TableView style={{flex:1}} 
         allowsToggle={true} 
         allowsMultipleSelection={true} 
         tableViewStyle={TableView.Consts.Style.Grouped} 
         tableViewCellStyle={TableView.Consts.CellStyle.Subtitle} 
         onPress={(event) => console.log(event)}> 
       <Section label="Section 1" arrow={true}> 
        <Item value="1" detail="Detail1" >Item 1</Item> 
        <Item value="2">Item 2</Item> 
       </Section> 
       <Section label="Section 2" arrow={false}> 
        <Item selected={true}>Item 1</Item> 
        <Item>Item 2</Item> 
        <Item>Item 3</Item> 
       </Section> 
      </TableView> 
     ); 
    } 
} 

AppRegistry.registerComponent('AwesomeProject',() => AwesomeProject); 

依賴關係:

"dependencies": { 
    "react-native": "^0.17.0", 
    "react-native-navbar": "^1.1.6", 
    "react-native-router": "^0.2.1", 
    "react-native-tableview": "^1.4.6" 
} 

而我得到的錯誤:

Error building DependencyGraph: 
Error: Naming collision detected: /Users/sandbox/native/test/AwesomeProject/node_modules/react-native-router/node_modules/react-native/packager/react-packager/src/DependencyResolver/haste/polyfills/String.prototype.es6.js collides with /Users/sandbox/native/test/AwesomeProject/node_modules/react-native/packager/react-packager/src/Resolver/polyfills/String.prototype.es6.js 
    at HasteMap._updateHasteMap (HasteMap.js:123:13) 
    at HasteMap.js:94:28 
    at tryCallOne (/Users/sandbox/native/test/AwesomeProject/node_modules/promise/lib/core.js:37:12) 
    at /Users/sandbox/native/test/AwesomeProject/node_modules/promise/lib/core.js:123:15 
    at flush (/Users/sandbox/native/test/AwesomeProject/node_modules/asap/raw.js:50:29) 
    at doNTCallback0 (node.js:417:9) 
    at process._tickCallback (node.js:346:13) 

我注意到很多人遇到這個問題,但仍然沒有明確的解決方案,哪個庫是有罪的y以及如何避免它。

回答

2

錯誤表示有String.prototype.es6.js的兩個副本,並且打包程序無法忽略其中的一個,因此您收到錯誤。

您使用npm2還是npm3?作爲一種解決方法,npm3將平抑依賴關係,這將允許您通過重複反應(假設您確保它們都指向相同版本)來前進。

您可以將install npm3作爲單獨的全局包裝運行,然後運行npm3 install或者您可以通過npm install -g [email protected]升級整個npm包。另外,如果您選擇升級,請務必在重新安裝npm軟件包之前刪除node_modules目錄中的內容。

這種方法有很多優缺點,並且反應本地可能包括React作爲可能緩解此問題的對等關係。它似乎並不像react-native-router必然需要經常React,因爲使用的組件依賴於react-native,所以如果您仍然遇到npm3或不希望出現問題,可能值得分解此回購並刪除對React的直接依賴關係用它。

+0

謝謝你的回答。我也在GitHub上看到過,並且是'react-native-router'使用舊版本的react-native,現在它已經修復https://github.com/t4t5/react-native-router/commit/8ee6c940b025bfe69e1033bf15af14f55faae4e6但尚未發佈 –