|
1 | | -// Load compiled Dart app |
| 1 | +// Heavy diagnostics for debugging |
2 | 2 | console.log('=== INDEX.JS STARTING ==='); |
| 3 | +console.log('=== Checking globals ==='); |
| 4 | +console.log('typeof global:', typeof global); |
| 5 | +console.log('typeof require:', typeof require); |
| 6 | + |
| 7 | +// Import React and React Native FIRST |
| 8 | +console.log('=== Importing React ==='); |
| 9 | +const React = require('react'); |
| 10 | +console.log('React loaded:', !!React); |
| 11 | +console.log('React.createElement:', typeof React.createElement); |
| 12 | + |
| 13 | +console.log('=== Importing React Native ==='); |
| 14 | +const ReactNative = require('react-native'); |
| 15 | +console.log('ReactNative loaded:', !!ReactNative); |
| 16 | +console.log('AppRegistry:', typeof ReactNative.AppRegistry); |
| 17 | +console.log('View:', typeof ReactNative.View); |
| 18 | +console.log('Text:', typeof ReactNative.Text); |
| 19 | + |
| 20 | +// Make React and ReactNative available globally for Dart |
| 21 | +// Dart's @JS() looks at 'self' which the node preamble sets up |
| 22 | +console.log('=== Setting up globals for Dart ==='); |
| 23 | +global.React = React; |
| 24 | +global.ReactNative = ReactNative; |
| 25 | +global.reactNative = ReactNative; |
| 26 | + |
| 27 | +// Also set on self/this for Dart JS interop |
| 28 | +if (typeof self !== 'undefined') { |
| 29 | + console.log('Setting on self...'); |
| 30 | + self.React = React; |
| 31 | + self.ReactNative = ReactNative; |
| 32 | + self.reactNative = ReactNative; |
| 33 | +} |
| 34 | +// For React Native, also set on globalThis |
| 35 | +if (typeof globalThis !== 'undefined') { |
| 36 | + console.log('Setting on globalThis...'); |
| 37 | + globalThis.React = React; |
| 38 | + globalThis.ReactNative = ReactNative; |
| 39 | + globalThis.reactNative = ReactNative; |
| 40 | +} |
| 41 | + |
| 42 | +console.log('global.React set:', !!global.React); |
| 43 | +console.log('global.reactNative set:', !!global.reactNative); |
| 44 | +console.log('Checking self.React:', typeof self !== 'undefined' ? !!self.React : 'self undefined'); |
| 45 | +console.log('Checking globalThis.React:', typeof globalThis !== 'undefined' ? !!globalThis.React : 'globalThis undefined'); |
| 46 | + |
| 47 | +// Load compiled Dart app |
| 48 | +console.log('=== Loading Dart app.js ==='); |
3 | 49 | try { |
4 | | - console.log('Loading app.js...'); |
5 | 50 | require('../build/app.js'); |
6 | | - console.log('=== APP.JS LOADED ==='); |
| 51 | + console.log('=== APP.JS LOADED SUCCESSFULLY ==='); |
7 | 52 | } catch (e) { |
8 | | - console.error('=== ERROR LOADING APP.JS ===', e); |
| 53 | + console.error('=== ERROR LOADING APP.JS ==='); |
| 54 | + console.error('Error:', e.message); |
| 55 | + console.error('Stack:', e.stack); |
| 56 | + |
| 57 | + // Register a fallback error component |
| 58 | + console.log('=== Registering fallback error component ==='); |
| 59 | + const { AppRegistry, View, Text } = ReactNative; |
| 60 | + |
| 61 | + const ErrorApp = () => { |
| 62 | + return React.createElement( |
| 63 | + View, |
| 64 | + { style: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'red' } }, |
| 65 | + React.createElement( |
| 66 | + Text, |
| 67 | + { style: { color: 'white', fontSize: 18, textAlign: 'center', padding: 20 } }, |
| 68 | + 'Error loading Dart app: ' + e.message |
| 69 | + ) |
| 70 | + ); |
| 71 | + }; |
| 72 | + |
| 73 | + AppRegistry.registerComponent('DartMobile', () => ErrorApp); |
9 | 74 | } |
| 75 | + |
| 76 | +console.log('=== INDEX.JS COMPLETE ==='); |
0 commit comments