Skip to content

Commit 88848ef

Browse files
authored
fix: metro js crypto module build issues (#1047)
* fix sdk build issues * fix build error * sort and fix dependencies * add constants-browserify
1 parent b26aca0 commit 88848ef

5 files changed

Lines changed: 242 additions & 15 deletions

File tree

app/metro.config.cjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,36 @@ const config = {
220220
],
221221
assetExts: assetExts.filter(ext => ext !== 'svg'),
222222
sourceExts: [...sourceExts, 'svg'],
223+
224+
// Custom resolver to handle Node.js modules elegantly
225+
resolveRequest: (context, moduleName, platform) => {
226+
// Handle problematic Node.js modules that don't work in React Native
227+
const nodeModuleRedirects = {
228+
crypto: require.resolve('crypto-browserify'),
229+
fs: false, // Disable filesystem access
230+
os: false, // Disable OS-specific modules
231+
readline: false, // Disable readline module
232+
constants: require.resolve('constants-browserify'),
233+
path: require.resolve('path-browserify'),
234+
};
235+
236+
if (
237+
Object.prototype.hasOwnProperty.call(nodeModuleRedirects, moduleName)
238+
) {
239+
if (nodeModuleRedirects[moduleName] === false) {
240+
// Return empty module for disabled modules
241+
return { type: 'empty' };
242+
}
243+
// Redirect to polyfill
244+
return {
245+
type: 'sourceFile',
246+
filePath: nodeModuleRedirects[moduleName],
247+
};
248+
}
249+
250+
// Fall back to default Metro resolver for all other modules
251+
return context.resolveRequest(context, moduleName, platform);
252+
},
223253
},
224254
watchFolders,
225255
};

app/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
"@tamagui/config": "1.126.14",
9696
"@tamagui/lucide-icons": "1.126.14",
9797
"@tamagui/toast": "^1.127.2",
98-
"@tamagui/vite-plugin": "1.126.14",
9998
"@xstate/react": "^5.0.3",
10099
"add": "^2.0.6",
101100
"asn1js": "^3.0.6",
@@ -139,7 +138,6 @@
139138
"socket.io-client": "^4.8.1",
140139
"tamagui": "1.126.14",
141140
"uuid": "^11.1.0",
142-
"vite-plugin-svgr": "^4.5.0",
143141
"xstate": "^5.20.2",
144142
"zustand": "^4.5.2"
145143
},
@@ -153,6 +151,7 @@
153151
"@react-native/metro-config": "0.76.9",
154152
"@react-native/typescript-config": "0.76.9",
155153
"@tamagui/types": "1.126.14",
154+
"@tamagui/vite-plugin": "1.126.14",
156155
"@testing-library/react-hooks": "^8.0.1",
157156
"@testing-library/react-native": "^13.3.3",
158157
"@tsconfig/react-native": "^3.0.6",
@@ -161,6 +160,7 @@
161160
"@types/elliptic": "^6",
162161
"@types/jest": "^29.5.14",
163162
"@types/node-forge": "^1.3.14",
163+
"@types/path-browserify": "^1",
164164
"@types/react": "^18.3.4",
165165
"@types/react-dom": "^18.3.0",
166166
"@types/react-native-dotenv": "^0.2.0",
@@ -171,6 +171,8 @@
171171
"@typescript-eslint/parser": "^8.39.0",
172172
"@vitejs/plugin-react-swc": "^3.10.2",
173173
"babel-plugin-module-resolver": "^5.0.2",
174+
"constants-browserify": "^1.0.0",
175+
"crypto-browserify": "^3.12.1",
174176
"dompurify": "^3.2.6",
175177
"eslint": "^8.57.0",
176178
"eslint-config-prettier": "10.1.8",
@@ -183,6 +185,7 @@
183185
"eslint-plugin-simple-import-sort": "^12.1.1",
184186
"eslint-plugin-sort-exports": "^0.9.1",
185187
"jest": "^29.6.3",
188+
"path-browserify": "^1.0.1",
186189
"prettier": "^3.5.3",
187190
"react-native-svg-transformer": "^1.5.1",
188191
"react-test-renderer": "^18.3.1",
@@ -191,7 +194,8 @@
191194
"ts-morph": "^22.0.0",
192195
"ts-node": "^10.9.2",
193196
"typescript": "^5.9.2",
194-
"vite": "^7.0.0"
197+
"vite": "^7.0.0",
198+
"vite-plugin-svgr": "^4.5.0"
195199
},
196200
"packageManager": "[email protected]",
197201
"engines": {

app/scripts/bundle-analyze-ci.cjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ if (!platform || !['android', 'ios'].includes(platform)) {
1616

1717
// Bundle size thresholds in MB - easy to update!
1818
const BUNDLE_THRESHOLDS_MB = {
19-
ios: 36,
20-
android: 36,
19+
// TODO: fix temporary bundle bump
20+
ios: 42,
21+
android: 42,
2122
};
2223

2324
function formatBytes(bytes) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"types": "yarn workspaces foreach --topological-dev --parallel --exclude @selfxyz/contracts -i --all run types "
3030
},
3131
"resolutions": {
32-
"@typescript-eslint/eslint-plugin": "^8.39.0",
33-
"@typescript-eslint/parser": "^8.39.0",
3432
"@babel/core": "^7.28.3",
3533
"@babel/runtime": "^7.28.3",
34+
"@typescript-eslint/eslint-plugin": "^8.39.0",
35+
"@typescript-eslint/parser": "^8.39.0",
3636
"react": "^18.3.1",
3737
"react-native": "0.76.9"
3838
},

0 commit comments

Comments
 (0)