2016-01-13 53 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但尚未发布 –