android - 错误 : jest-haste-map: Haste module naming collision:

标签 android react-native npm npm-install yarnpkg

我已经创建了一个自定义的 npm 模块(将使用 xxx 而不是它的名称)并使用 npm install 手动链接它。

我非常努力地搜索:

在提出问题之前。如果有人告诉我我的代码或我的方法有什么问题或我的代码中有任何错误,我将不胜感激。

当我运行 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>
        );
    }
}

我使用自定义模块的文件是

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"
    }
});

我尝试了 npm install/absolute/path/to/xxx 并且它正确地链接了模块。正确地说,我的意思是我可以在 nodemodule 目录中看到 react-native-xxx 包。 我尝试了所有可能的方法,但没有任何效果。

我也试过,但没有成功

  • yarn 添加/absolute/path/to/react-native-xxx
  • react-native 链接 react-native-xxx
  • react-native run-android

最佳答案

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

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

see this issue

希望对你有用

关于android - 错误 : jest-haste-map: Haste module naming collision:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54108310/

相关文章:

java - SearchView 主题更改

android - 在 Android Pie 上启动 context.startService(intent)

reactjs - react native 中带/flexbox 的全宽按钮

javascript - 在浏览器中使用 Node Rework CSS

node.js - 安装 npm 包时出现“node-gyp”错误

android - 在 Android 中获取通知接收时间

android - Delphi android 创建操作栏

android - 如何在 React-native 项目中找到应用程序文件夹路径

javascript - React Native this._lazyCallableModules[name] 不是函数

node.js - IBM Bluemix - NodeJS : unable to resolve the dependency in the manifest