Fir*_*iru 13 android npm react-native npm-install yarnpkg
我创建了一个自定义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.
Run Code Online (Sandbox Code Playgroud)
我的自定义模块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"
}
}
Run Code Online (Sandbox Code Playgroud)
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>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用自定义模块的文件是
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"
}
});
Run Code Online (Sandbox Code Playgroud)
我试过了npm install /absolute/path/to/xxx,它正确链接了模块。正确地说,我可以react-native-xxx在nodemodule目录中看到软件包。我做了所有可能的方法,但是没有任何效果。
我也尝试过但没有成功
小智 5
在根项目中添加 rn-cli.config.js
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/node_modules\/.*\/node_modules\/react-native\/.*/,
])
},
};
Run Code Online (Sandbox Code Playgroud)
希望对你有帮助
您收到的错误表明您有两个react-native依赖项。一个在您的主项目中,一个在您的 xxx 模块中,从而在它们之间产生冲突package.json。似乎如果您从本地路径安装软件包,它会复制其node_modules目录。
由于您react-native的自定义模块中已经存在对等依赖项package.json,请尝试删除E:\cdg-native\CDG\node_modules\react-native-XXX\node_modules,这应该可以解决冲突。
| 归档时间: |
|
| 查看次数: |
8218 次 |
| 最近记录: |