← 输入框|github.com|刷新
Skip to content

vite: extractDirectExportedNames matches 'export' inside comments, producing phantom CJS exports #11471

Closed

Description

@aleclarson

Build-time / dev-server error in @nativescript/vite (observed on 8.0.11, same code on main).

Description

extractDirectExportedNames (hmr/server/websocket-core-bridge.ts) scans CJS sources for export declarations with regexes like /\bexport\s+(?:const|let|var)\s+.../ — but it never masks comments first. A commented-out line such as:

// export const roundRadiusProperty = ...

still matches, so wrapCommonJsModuleForDevice emits export { roundRadiusProperty } for a binding that doesn't exist. On device this fails at link time:

SyntaxError: Importing binding name 'roundRadiusProperty' cannot be resolved

and the dev-session boot aborts (the error surfaces as an opaque HTTP-ESM instantiation failure).

Repro: @nativescript-community/ui-image@8's index-common.js contains commented-out export const lines; importing it over /ns/m in dev mode reproduces the failure.

Suggested fix

Strip line/block comments (carefully — string literals may contain //) before running the export regexes, or reuse the existing es-module-lexer/CJS analysis pass if available. Masking comments in our patched copy fixed the boot.

Environment: @nativescript/vite 8.0.11, Vite 8.3, iOS simulator.

Activity

  1. aleclarson commented on Sep 28, 2026

    @aleclarson
    ContributorAuthor

    Minimal reproduction: https://github.com/aleclarson/repro/tree/nativescript-11471 — a single Node script (npm install && node repro.mjs) that exercises the exact upstream function/code path and prints the failure.

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