android - 错误:jest-haste-map:Haste 模块命名冲突:
问题描述
我创建了一个自定义npm module
(将使用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
了,它正确链接了模块。正确的意思是我可以在目录中看到react-native-xxx
包。nodemodule
我做了所有可能的方法,但没有任何效果。
我也试过但没有成功
- 纱线添加 /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\/.*/,
])
},
};
希望这对你有用
推荐阅读
- ftp - 200 PORT 命令成功。考虑使用 PASV。425 无法建立连接(Windown 笔记本电脑)
- python - 需要在同一页面中获取输出(使用带有ajax的django模型表单)
- ios - 如何在 SwiftUI 中添加背景图像以完成视图
- java - 如何在 AdoptOpenJDK 11 和 JavaFX 11 上使用 VM 参数执行 .Jar 文件?
- dialogflow-es - 是否有可能从同一输入中找到多个意图
- java - spring boot 哪个“切片”用于测试服务组件
- android - 如何从 JSON 响应中获取此“id”值?
- type-conversion - 从字符串转换为十进制时 ADF 复制活动失败
- php - 在数组中按值查找元素并取消设置元素
- excel - 计算一年内日期和客户等于的行数