Android 错误:jest haste映射:haste模块命名冲突:

Android 错误:jest haste映射:haste模块命名冲突:,android,react-native,npm,npm-install,yarnpkg,Android,React Native,Npm,Npm Install,Yarnpkg,我已经创建了一个定制的npm模块(将使用xxx而不是其名称),并使用npm安装手动链接它 我非常努力地寻找: 在提出问题之前。如果有人告诉我我的代码或方法有什么问题,或者代码中有什么错误,我会非常感激 当我运行react native run android时,metro bundler Error: jest-haste-map: Haste module naming collision: Duplicate module name: react-native Paths:

我已经创建了一个定制的
npm模块
(将使用xxx而不是其名称),并使用
npm安装
手动链接它

我非常努力地寻找:

在提出问题之前。如果有人告诉我我的代码或方法有什么问题,或者代码中有什么错误,我会非常感激

当我运行
react native run android
时,
metro bundler

Error: jest-haste-map: Haste module naming collision:
  Duplicate module name: react-native
  Paths: E:\cdg-native\CDG\node_modules\react-native-XXX\node_modules\react-native\package.json collides with E:\cdg-native\CDG\node_modules\react-native\package.json

This error is caused by `hasteImpl` returning the same name for different files.
我的自定义模块
package.json

{
  "name": "react-native-xxx",
  "version": "1.0.0",
  "description": "Library to render xxx",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "react native xxx"
  ],
  "author": "Firdous Nath",
  "license": "ISC",
  "peerDependencies": {
    "react": "*",
    "react-native": "*"
  },
  "devDependencies": {
    "react": "^16.6.1",
    "react-native": "^0.57.5",
    "babel-cli": "^6.26.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1"
  }
}
自定义模块的
index.js
非常简单,如下所示

import React from "react";
import { Text } from "react-native";

export default class XXXView extends React.Component {

    render() {
        return (
            <Text> From custom module </Text>
        );
    }
}
从“React”导入React;
从“react native”导入{Text};
导出默认类XXXView.Component{
render(){
返回(
来自自定义模块
);
}
}
我正在使用自定义模块的文件是

import React from "react";
import {StyleSheet, View} from "react-native";
import XXXView from "react-native-xxx"
//import {XXXView} from "react-native-xxx" -> I tried this as well

export default class App extends React.Component {
    render() {
        return (
            <View style={styles.container}>
                <XXXView/>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
        backgroundColor: "#f5fcff"
    }
});
从“React”导入React;
从“react native”导入{StyleSheet,View};
从“反应本机xxx”导入XXXView
//从“react native xxx”导入{XXXView}->我也尝试过这个
导出默认类App扩展React.Component{
render(){
返回(
)
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
辩护内容:“中心”,
对齐项目:“中心”,
背景颜色:“f5fcff”
}
});
我尝试了
npm安装/absolute/path/to/xxx
,它正确地链接了模块。正确地说,我的意思是我可以在
nodemodule
目录中看到
react native xxx
包。 我做了所有可能的方法,但没有任何效果

我也试过了,但没有成功

  • 纱线添加/绝对/路径/到/反应本地xxx
  • 反应本机链接反应本机xxx
  • react本地运行的android

您得到的错误表明您有两个
react-native
依赖项。一个在主项目中,一个在xxx模块中,从而在它们的
package.json
s之间产生冲突。似乎如果您从本地路径安装包,它会复制其
node\u modules
目录


由于自定义模块的
package.json
中已有
react native
作为对等依赖项,请尝试删除
E:\cdg native\cdg\node\u modules\react native XXX\node\u modules
,这将解决冲突。

在根项目中添加rn cli.config.js

const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
 resolver: {
    blacklistRE: blacklist([
        /node_modules\/.*\/node_modules\/react-native\/.*/,
    ])
 },
};


希望它能为您工作

看起来您有两个不同的react本机项目文件夹,其中一个文件夹依赖于另一个文件夹(它被包含为节点\模块依赖项),并且您似乎正在运行服务器启动(“react本机启动”)来自库文件夹的命令。

感谢您的回复,但每当我运行npm安装节点时,都会创建模块。如果我发布包,其他人也会遇到同样的问题。实际上,如果指定的依赖项已经存在于依赖您的自定义模块的项目中,它将不会将其复制到自己的node_modules文件夹中(至少看起来是这样)。当我查看节点模块中的react native dep时,我看到它的node_modules文件夹中有几个dep,但绝大多数都在项目的模块中folder@luky你用Pod吗?@zhouDai,那个解决方案对我也不起作用。@Daniel你用Pod吗?@zhouDai,是的,我有。@Daniel添加'post_install do | installer | installer.pods|u project.targets.each do | target | if target.name==“React”target.remove_from_project end”在podfiles结束时,节省了我一天的时间…在我的项目中有另一个React原生项目。刚刚删除了不需要的项目,然后爆炸!