【发布时间】:2019-03-22 10:53:45
【问题描述】:
我在 react-native 0.54.0 (Expo SDK 26) 中使用来自 node 的 url.parse
const url = require("url");
const { hostname, pathname } = url.parse(props.currentMessage.image);
var extension = pathname.substr(pathname.lastIndexOf(".") + 1);
// determine file URL
const fileURL = `https://${hostname}${pathname}`;
当更新到 SDK 27 并转移到 RN 0.55.2 时,我遇到了这个问题
您试图从“src/modules/xxx/xxx.js”导入 Node 标准库模块“url”。它失败了,因为 React Native 不包含 Node 标准库。阅读更多https://docs.expo.io/versions/latest/introduction/faq.html#can-i-use-nodejs-packages-with-expo
几个问题:
这和我的实现有关吗?
好像和 React-native 有关系,等我更新到 SDK 28、29、30 后会自行解决吗?
是否有任何替代方法可以让我在不添加任何其他依赖项的情况下做同样的事情?
(ps:不需要为这个简单的用例建议依赖项,例如'url'或'whatwg-url',我不会那样做)
【问题讨论】:
标签: reactjs react-native expo