Skip to content

Conversation

@hendrickson-tyler
Copy link
Contributor

Description

With v4 of the unit test runner, ES Module syntax is mixed with commonJS syntax in a couple of files. As a result, the unit test runner fails to run out of the box with NativeScript v9 because exports is not defined.

This PR updates those files to use proper ES Module syntax throughout, which resolves the error.

Error

ns test ios
Searching for devices...
02 12 2025 15:58:46.881:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead.
02 12 2025 15:58:47.052:WARN [karma]: No captured browser, open http://127.0.0.1:9876/
02 12 2025 15:58:47.060:INFO [karma-server]: Karma v6.4.4 server started at http://127.0.0.1:9876/
02 12 2025 15:58:47.060:INFO [launcher]: Launching browsers ios with concurrency unlimited
02 12 2025 15:58:47.063:INFO [launcher]: Starting browser NativeScript Unit Test Runner
Copying template files...
Platform ios successfully added. v9.0.1
Preparing project...
webpack is watching the files...
asset vendor.mjs 3.53 MiB [emitted] [javascript module] (name: vendor) (id hint: vendor) 1 related asset
asset bundle.mjs 7.98 KiB [emitted] [javascript module] (name: bundle) 1 related asset
asset runtime.mjs 5.69 KiB [emitted] [javascript module] (name: runtime) 1 related asset
asset tns_modules/inspector_modules.mjs 998 bytes [emitted] [javascript module] (name: tns_modules/inspector_modules) 1 related asset
Entrypoint bundle 3.55 MiB (3.96 MiB) = runtime.mjs 5.69 KiB vendor.mjs 3.53 MiB bundle.mjs 7.98 KiB 3 auxiliary assets
Entrypoint tns_modules/inspector_modules 3.54 MiB (3.95 MiB) = runtime.mjs 5.69 KiB vendor.mjs 3.53 MiB tns_modules/inspector_modules.mjs 998 bytes 3 auxiliary assets
orphan modules 105 KiB [orphan] 27 modules
runtime modules 2.95 KiB 6 modules
modules by path ./node_modules/@nativescript/ 2.02 MiB 239 modules
modules by path ./node_modules/css-tree/lib/ 318 KiB 123 modules
modules by path ./node_modules/source-map-js/ 102 KiB 11 modules
modules by path ./node_modules/@csstools/ 132 KiB
  ./node_modules/@csstools/css-calc/dist/index.mjs 28.3 KiB [built] [code generated]
  + 4 modules
modules by path ./node_modules/css-what/dist/esm/*.js 24.9 KiB
  ./node_modules/css-what/dist/esm/index.js 121 bytes [built] [code generated]
  + 3 modules
modules by path ./src/ 556 bytes
  ./src/test.ts 206 bytes [built] [code generated]
  + 2 modules
+ 5 modules
webpack 5.103.0 compiled successfully in 3188 ms
Webpack compilation complete. Watching for file changes.
Updating runtime package.json with configuration values...
Project successfully prepared (ios)
Building project...
Xcode build...
Project successfully built.
Build time: 16.074 s.
The build result is located at: /Users/tylerhendrickson/Downloads/example-app/platforms/ios/build/Debug-iphonesimulator/exampleapp.app
Installing on device 782F98A5-3AB9-4E9E-91AA-0F88F9DD0F73...
Successfully installed on device with identifier '782F98A5-3AB9-4E9E-91AA-0F88F9DD0F73'.
Successfully transferred all files on device 782F98A5-3AB9-4E9E-91AA-0F88F9DD0F73.
Restarting application on device 782F98A5-3AB9-4E9E-91AA-0F88F9DD0F73...
Successfully synced application org.nativescript.exampleapp on device 782F98A5-3AB9-4E9E-91AA-0F88F9DD0F73.
  NSUTR: fetching http://127.0.0.1:9876/context.json
  NSUTR: fetching http://192.168.1.156:9876/context.json
  bundle-app-root.xml
  NSUTR: uncaught error
  NSUTR: this.error: Building UI from XML. @bundle-app-root.xml:1:1
   > exports is not defined
  NSUTR: completed test run.
  ***** JavaScript exception occurred in debug mode *****
  Uncaught Error: Building UI from XML. @bundle-app-root.xml:1:1
   > exports is not defined
   at
  ReferenceError: exports is not defined
      at ./node_modules/@nativescript/unit-test-runner/app/bundle-main-page.js (file:///app/vendor.mjs:53036:1)
      at __webpack_require__ (file:///app/runtime.mjs:21:41)
      at webpackContext (file:///app/bundle.mjs:58:9)
      at Object.loader (file:///app/vendor.mjs:9225:24)
      at loadModule (file:///app/vendor.mjs:9346:35)
      at Builder.createViewFromEntry (file:///app/vendor.mjs:15976:61)
      at Frame.navigate (file:///app/vendor.mjs:24944:68)
      at valueChanged (file:///app/vendor.mjs:25433:15)
      at Property.set [as defaultPage] (file:///app/vendor.mjs:18167:25)
      at setPropertyValue (file:///app/vendor.mjs:15872:32)
  ReferenceError: exports is not defined
      at ./node_modules/@nativescript/unit-test-runner/app/bundle-main-page.js (file:///app/vendor.mjs:53036:1)
      at __webpack_require__ (file:///app/runtime.mjs:21:41)
      at webpackContext (file:///app/bundle.mjs:58:9)
      at Object.loader (file:///app/vendor.mjs:9225:24)
      at loadModule (file:///app/vendor.mjs:9346:35)
      at Builder.createViewFromEntry (file:///app/vendor.mjs:15976:61)
      at Frame.navigate (file:///app/vendor.mjs:24944:68)
      at valueChanged (file:///app/vendor.mjs:25433:15)
      at Property.set [as defaultPage] (file:///app/vendor.mjs:18167:25)
      at setPropertyValue (file:///app/vendor.mjs:15872:32)
  ***** End stack trace - Fix error to continue *****
  NSUTR: found karma at 127.0.0.1
  NSUTR: connecting to karma at http://127.0.0.1:9876
  NSUTR: found karma at 192.168.1.156
  NSUTR: successfully connected to karma
02 12 2025 15:59:22.020:INFO [NativeScript / 26.1 (26.1; iPhone)]: Connected on socket NY3NbY3Y77CxNpCIAAAB with id NativeScriptUnit-2025
  NSUTR: completeAck
  NSUTR-socket.io: io client disconnect
02 12 2025 15:59:22.986:WARN [NativeScript / 26.1 (26.1; iPhone)]: Disconnected (0 times) Client disconnected from CONNECTED state (client namespace disconnect)
NativeScript / 26.1 (26.1; iPhone) ERROR
  Disconnected Client disconnected from CONNECTED state (client namespace disconnect)

Reproduction

Create a new NativeScript Angular application with the following command:

ns create example-app --ng

After the project is created, initialize the unit test runner at the root of the project with:

ns test init

Select Jasmine, when prompted. Finally, run the tests on iOS with:

ns test ios

This will present in the error mentioned above.

@NathanWalker NathanWalker merged commit 64d405a into NativeScript:main Dec 3, 2025
@NathanWalker
Copy link
Contributor

Thank you @hendrickson-tyler it's in 4.0.1 now.

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.

2 participants