【发布时间】:2019-06-28 10:06:33
【问题描述】:
stream 不能与 expo 一起使用,因为它是 Node.js 标准包。但是,stream-browserify 包可以在这些情况下用作替代方案。
为了让模块而不是原生 Node 包解决这个问题,我试图让 babel-plugin-require-rewrite 与 expo 一起工作。
我将此添加到babel.config.js:
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: [
["rewrite-require", { aliases: {
"stream": "stream-browserify"
}}]
]
};
};
不幸的是,捆绑器不尊重它。尝试时出现此错误:
The package at "node_modules\qr-image\lib\qr.js" attempted to import the Node standard library module "stream". It failed because React Native does not include the Node standard library. Read more at https://docs.expo.io/versions/latest/introduction/faq.html#can-i-use-nodejs-packages-with-expo
是否有可能在世博会上进行这项工作?
【问题讨论】:
-
您是否尝试过使用
rn-nodeify? (github.com/tradle/rn-nodeify) 似乎人们将它与你想使用的库一起使用github.com/tradle/rn-nodeify/issues/32 -
真的没用。我不知道为什么,确切地说。我创建了一个包含详细信息的问题:github.com/tradle/rn-nodeify/issues/77
-
如果您明确尝试使用
stream,新版本的 Expo 已经带有移植的stream版本。继续var stream = require('stream');。我使用的是 Expo 2.6.14 版。 -
您使用的是哪个 Expo 版本?你试过
require('stream')吗?您甚至不需要将它添加到 package.json。并非所有软件包都被移植。例如,crypto不起作用。
标签: react-native babeljs expo