Skip to content

Conversation

@NathanWalker
Copy link
Contributor

@NathanWalker NathanWalker commented Jul 16, 2025

  • Conditionally detects .mjs (esm) or .js bundled code
  • Loads and executes ES modules
  • When module or javascript errors occur, they are caught and proper file/line numbers are printed for better diagnosing

Backwards compatible.

New nativescript.config options

  1. logScriptLoading: true: Used to enable verbose terminal output on module resolution.
  2. 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.

@NathanWalker NathanWalker added this to the 9.0 milestone Jul 16, 2025
@NathanWalker NathanWalker changed the title feat: allow conditional esm consumption + better error handling feat: ES modules (ESM) support with conditional esm or commonjs consumption + better error handling Jul 25, 2025
@NathanWalker NathanWalker marked this pull request as draft October 9, 2025 06:14
@NathanWalker NathanWalker requested a review from Copilot October 23, 2025 17:09
Copy link

Copilot AI left a 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 .mjs file 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 showErrorDisplay config 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());
Copy link

Copilot AI Oct 23, 2025

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'.

Copilot uses AI. Check for mistakes.
NathanWalker and others added 2 commits October 24, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant