Skip to content

Vite Vue HMR redirects similarly named packages and emits an obsolete vendor import #11554

Open

Description

@rafaelaugustos

Issue Description

On @nativescript/vite 8.0.19, Vue HTTP-module import rewriting can redirect unrelated packages to the Vue runtime and generate an obsolete vendor URL for a native Vue dependency. Found while adding Vite to vue-router-ns (rafaelaugustos/vue-router-ns#100).

Two deterministic reproductions against NativeScript main 3224f1b:

  1. Pass import { createRouter } from '/node_modules/.vite/deps/vue-router-ns.js?v=abc' through astNormalizeModuleImportsAndHelpers. The dependency is replaced by /ns/rt. The prebundle matcher accepts any filename starting with vue; vue-demi and nativescript-vue-router are affected too. Bare nativescript-vue-router also matches the loose includes('nativescript-vue') check.
  2. Pass a module importing { $navigateTo, ref } from bare nativescript-vue through cleanCode(source, vueServerStrategy), processCodeForDevice, and rewriteImports. Framework rewriting first emits /@nativescript/vendor.mjs; later passes also inject $navigateTo from /ns/rt, producing duplicate bindings and an HTTP request to /ns/m/@nativescript/vendor.mjs (404).

Expected: only Vue runtime imports reach /ns/rt; unrelated packages retain their own exports; native navigation helpers share the canonical bridge without duplicate declarations.

Native reproduction and limits

Android 16/API 36 emulator, Node 22.23.3, CLI 9.1.2, Core 9.1.3, NativeScript-Vue 3.1.2, Vite 8.3.4, @nativescript/vite 8.0.19. The second failure was captured in a per-module-served, locally linked vue-router-ns/dist/hosts/frame.js. Normal packed dependencies can take the deps-bundle path and avoid this particular raw-module failure.

Related to #11421, but this report does not claim to reproduce or fix every path in that older report. Bundled --no-hmr navigation passes on Android and iOS. A separate native SFC macro-transform bypass still blocks file-routing HMR, so fixing these imports alone is not full end-to-end HMR support.

A patch with regression tests is prepared. Tests reproduce both failures before the patch and pass after it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions