react-native - 如何使用 Expo 解决“重复的模块名称:react-native”
问题描述
使用我自己的 npm 包时,我不断收到以下错误,这也取决于react-native
:
jest-haste-map: @providesModule naming collision:
Duplicate module name: react-native
Paths: /reproducible-bug-examples/duplicate-module-name-npm/node_modules/react-native/package.json collides with /reproducible-bug-examples/duplicate-module-name/node_modules/react-native/package.json
This error is caused by a @providesModule declaration with the same name across two different files.
package.json
为duplicate-module-name-npm
:_
{
"name": "duplicate-module-name-npm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react": "16.5.0"
},
}
因为duplicate-module-name
它是:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject",
"test": "node ./node_modules/jest/bin/jest.js --watchAll"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@expo/samples": "2.1.1",
"expo": "^32.0.0",
"duplicate-module-name-npm": "file:../duplicate-module-name-npm",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-navigation": "^3.0.9"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0",
"jest-expo": "^32.0.0"
},
"private": true
}
我已经尝试过这里提到的解决方案,即添加一个rn-cli.config.js
,但问题仍然存在。实际上,在添加了此处描述的内容后,我得到了以下错误:
(node:31392) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
Duplicate module name: react-native
Paths: /reproducible-bug-examples/duplicate-module-name-npm/node_modules/react-native/package.json collides with /reproducible-bug-examples/duplicate-module-name/node_modules/react-native/package.json
This error is caused by a @providesModule declaration with the same name across two different files.
还尝试将以下内容添加到rn-cli-config.js
:
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/duplicate-module-name-npm\/.*/,
])
},
};
带有 MWE 的存储库可在https://github.com/zxl634/duplicate-module-name-npm和https://github.com/zxl634/duplicate-module-name获得。
运行后出现错误expo start
。
非常感谢任何帮助或建议:)
解决方案
通过添加路径的组合来解决它rn-cli.config.js
:
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/duplicate-module-name-npm\/node_modules\/react-native\/Libraries\/Sample\/.*/,
/duplicate-module-name-npm\/node_modules\/react-native\/react-native-git-upgrade\/.*/,
/duplicate-module-name-npm\/node_modules\/react-native\/react-native-cli\/.*/,
])
},
};
并更改导致问题的 package.json 文件中的“名称”字段,例如react-native/package.json
.
推荐阅读
- java - 在Java中将变量从一个类传递给另一个类总是给我一个空错误
- jquery - 切换类以重新触发动画
- python - Groupby 计数为一列和 groupby 熊猫中另一列的唯一值的数量
- c++ - 将 somedialog.h 包含到项目的其他部分使 ui_somedialog.h 对编译器不可见
- python - 有没有办法使用 python 修改输入设备的 DPI 或扫描分辨率?
- swift - 为什么 DispatchSemaphore.wait() 会阻止这个完成处理程序?
- github-actions - Github Actions:在特定操作系统上运行步骤
- flutter - Flutter 的 (Widget)State/StatefulWidget 模式的设计优势是什么?
- python-3.x - 机器学习:只能将 str(不是“int”)连接到 str
- linux - 如果某些参数不为空,则将 HTTP POST 请求重定向到另一个子域