-
-
Notifications
You must be signed in to change notification settings - Fork 37
feat: ES modules (ESM) support with conditional esm or commonjs consumption + better error handling #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…k to allow continued development during debug
With Vite, we just include inspector_modules in the bundle when running in debug mode so no need to load separate file. Other bundlers can do the same now.
…ght based on user choice
…l-esm-consumption
… release error throw handling
…l-esm-consumption
…l-esm-consumption
…l-esm-consumption
…l-esm-consumption
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds ES modules (ESM) support with conditional handling of .mjs vs .js bundled code, implements dynamic import() functionality, and enhances error handling in debug mode to prevent app crashes while providing detailed diagnostics through an optional on-device error display.
Key Changes:
- ES module loading with
.mjsfile detection, module resolution callbacks, and import.meta support - Enhanced error handling in debug mode that logs detailed stack traces without crashing the app
- Optional on-device error display modal (enabled via
showErrorDisplayconfig option)
Reviewed Changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
ModuleInternalCallbacks.mm/.h |
New files implementing ES module resolution, dynamic import callbacks, and Node.js polyfills |
ModuleInternal.mm/.h |
Extended to handle ESM vs CommonJS, improved error handling, and better module path resolution |
NativeScriptException.mm/.h |
Enhanced with optional error modal UI and graceful error handling in debug mode |
Runtime.mm/.h |
Added import.meta callback, module registry management, and config caching |
Worker.mm |
Improved error reporting and tilde path resolution for worker scripts |
Console.cpp/.h |
Added source map remapping and optional error display integration |
NativeScript.mm |
Infinite run loop in debug mode when errors occur to enable hot-reload |
| Test files | Added __setRuntimeIsDebug() calls to control error behavior during tests |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Failed to create file, fall back to throwing error | ||
| std::string msg = "Cannot find module " + spec + " (tried " + absPath + ")"; | ||
| if (RuntimeConfig.IsDebug) { | ||
| Log(@"Debug mode - Node.js polyfill creation failed: %s", msg.c_str()); |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'inititialization' to 'initialization'.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Backwards compatible.
New
nativescript.configoptionslogScriptLoading: true: Used to enable verbose terminal output on module resolution.showErrorDisplay: true: Used to display an error screen on the device when errors are encountered. Off by default. Some may prefer to see in terminal only as some will still allow app to continue fine. Other teams may want priority put on all errors that occur so rendering an error screen the moment they happen forces developer to handle them.