How to require Node Events module in React Native

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

How do I require the events Node module within my React Native project? I ran into some module dependency issues with util and http which I resolved by using Browserify to package.

I try to take the same approach with events:

npm install events var EventEmitter = require('events').EventEmitter;

After packaging with Browserify, I still get the same error from React Native: "Requiring unknown module 'events'."

回答1:

This is what you want: https://github.com/facebook/react-native/issues/1058

var EventEmitter = require('EventEmitter');



回答2:

I'm using events and a bunch of other node core modules by using react-native-webpack-server. It takes a bit of setup, but otherwise you're going to be running into the same problem with Buffer, assert, util, crypto, etc. Better take care of them all in one go.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!