react-native - 如何为第三方包做模块名称别名
问题描述
我有一个由react-native init命令创建的应用程序。我的应用程序导入 websocket 包,而该包又需要 http 包并导致错误提示“无法解析模块 http”。
即:myApp -> 3rd-module -> ws -> http
我尝试通过安装“@tradle/react-native-http”来解决问题,并将以下行添加到我的应用程序包 json 文件中:
"browser": { "http": "@tradle/react-native-http" },
"react-native": { "http": "@tradle/react-native-http" },
但它不起作用。
我也尝试使用 babel-plugin-module-resolver 但也不走运。这是我的 .babelrc :
{
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
["module-resolver", {
"alias": {
"@tradle/react-native-http": "http"
}
}]
]
}
如何为我的案例做别名?我研究通过使用 webpack 配置来解决这个问题,但不知道配置文件在哪里。在 google 之后,我认为react-native init创建的项目使用 Metro config 而不是 webpack。
解决方案
尝试
["module-resolver", {
"alias": {
"http":"@tradle/react-native-http"
}
}]
推荐阅读
- elasticsearch - 带有 gke 网络策略的 Elastic.co APM
- python - 模块“scipy.sparse”没有属性“linalg”
- algorithm - 平安夜问题:动态规划
- java - 如何在 ubuntu 中为 VS 代码配置和下载 Java JDK
- raspberry-pi2 - 使用 Raspi 2B 在 SonicPi 中没有音频
- r - 摘要功能不打印错误测量和准确性功能打印错误
- c++ - 两个应用程序的包装模块
- facebook - Facebook API 范围已删除
- php - 更改移动设备上 WooCommerce 产品的评论数量
- javascript - 基本反应原生问题隐蔽类到函数