From 06eb71e632d9d3fd0c1aa85f007ee3e63d23cfb9 Mon Sep 17 00:00:00 2001 From: James Pepper Date: Thu, 18 Sep 2025 23:14:45 +0100 Subject: [PATCH 1/2] Refactor Metro configuration and polyfills for improved compatibility Updated metro.config.js to add blockList and watchFolders for better module resolution and directory watching. Modified polyfills.js to replace the 'events' module with a custom EventEmitter implementation, enhancing compatibility with the current setup. --- metro.config.js | 23 ++++++++++------------- polyfills.js | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/metro.config.js b/metro.config.js index 61f60dab..7c30530f 100644 --- a/metro.config.js +++ b/metro.config.js @@ -29,18 +29,15 @@ config.resolver.alias = { // Ensure polyfills are resolved correctly config.resolver.sourceExts = [...config.resolver.sourceExts, 'cjs', 'mjs']; -// Add custom resolver to handle Node.js modules -config.resolver.resolveRequest = (context, moduleName, platform) => { - // Handle Node.js built-in modules - if (config.resolver.alias[moduleName]) { - return { - type: 'sourceFile', - filePath: require.resolve(config.resolver.alias[moduleName]), - }; - } - - // Fall back to default resolution - return context.resolveRequest(context, moduleName, platform); -}; +// Add blockList to exclude problematic files +config.resolver.blockList = [ + /node_modules\/.*\/node_modules\/react-native\/.*/, +]; + +// Add watchFolders to ensure Metro watches the correct directories +config.watchFolders = [ + __dirname, + `${__dirname}/node_modules`, +]; module.exports = config; diff --git a/polyfills.js b/polyfills.js index ae91ca72..10c931e6 100644 --- a/polyfills.js +++ b/polyfills.js @@ -56,7 +56,7 @@ global.require = (id) => { module = stream; break; case 'events': - module = require('events'); + module = { EventEmitter }; break; case 'util': module = require('util'); From 7394f2f56f8f985e15419648236e2d3ef2d65db2 Mon Sep 17 00:00:00 2001 From: James Pepper Date: Thu, 18 Sep 2025 23:18:30 +0100 Subject: [PATCH 2/2] Refactor events polyfill for improved module handling Updated polyfills.js to import the 'events' module as a whole instead of just the EventEmitter, enhancing the module's structure and ensuring better compatibility with the current setup. --- polyfills.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polyfills.js b/polyfills.js index 10c931e6..e6fe2179 100644 --- a/polyfills.js +++ b/polyfills.js @@ -16,8 +16,8 @@ import * as stream from 'stream-browserify'; global.stream = stream; // Events polyfill -import { EventEmitter } from 'events'; -global.EventEmitter = EventEmitter; +import * as events from 'events'; +global.EventEmitter = events.EventEmitter; // Util polyfill import util from 'util'; @@ -56,7 +56,7 @@ global.require = (id) => { module = stream; break; case 'events': - module = { EventEmitter }; + module = events; break; case 'util': module = require('util');