feat: ES modules (ESM) support with conditional esm or commonjs consumption + better error handling#276
Merged
NathanWalker merged 64 commits intomainfrom Nov 5, 2025
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
…l-esm-consumption
…l-esm-consumption
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…l-esm-consumption
NathanWalker
commented
Nov 5, 2025
NathanWalker
commented
Nov 5, 2025
NathanWalker
commented
Nov 5, 2025
triniwiz
approved these changes
Nov 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.