【问题标题】:Error building DependencyGraph: Error: Naming collision detected构建依赖关系图时出错:错误:检测到命名冲突
【发布时间】:2016-01-13 17:59:11
【问题描述】:

我正在使用 react-native-tableview 运行非常简单的代码

'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)

我注意到很多人都遇到过这个问题,但仍然没有明确的解决方案是哪个库有罪以及如何避免它。

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    错误表明String.prototype.es6.js 有两个副本,并且打包程序无法忽略其中一个,因此您收到了错误。

    您使用的是 npm2 还是 npm3?作为一种解决方法,npm3 将扁平化依赖项,这应该允许您通过重复数据删除 react 继续前进(假设您确保它们都指向相同的版本)。

    您可以将install npm3 作为一个单独的全局包然后运行npm3 install,或者您可以通过npm install -g npm@3.0-latest 升级整个npm 包。此外,如果您选择升级,请确保在重新安装 npm 包之前删除 node_modules 目录的内容。

    这种方法有利有弊,react-native 可能会将 React 作为对等依赖项包括在内,这可能会缓解这个问题。似乎react-native-router 不一定需要常规的React,因为正在使用的组件依赖于react-native,因此如果您仍然遇到@ 问题,可能值得分叉这个 repo 并删除对 React 的直接依赖987654330@或者不想用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 2015-08-03
    相关资源
    最近更新 更多