Skip to content

[suspicious-nullish-coalescing] warning from dead ?? [] fallback in virtual module codegen #15136

@cameronraysmith

Description

@cameronraysmith

Astro Info

Astro                    v5.16.7
Node                     v24.12.0
System                   macOS (arm64)
Package Manager          bun
Output                   static
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/starlight

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

JSON.stringify() always returns a string, so nullish coalescing on its interpolated output is dead code.

export const viteFSConfig = ${JSON.stringify(resolvedConfig.server.fs)} ?? {};

export const safeModulePaths = new Set(${JSON.stringify(
// @ts-expect-error safeModulePaths is internal to Vite
Array.from(resolvedConfig.safeModulePaths),
)} ?? []);

When safeModulePaths is empty, this generates:

new Set([] ?? []);

esbuild flags this during bundling (e.g., via wrangler):

▲ [WARNING] The "??" operator here will always return the left operand [suspicious-nullish-coalescing]

Likely introduced in

Runtime behavior seems correct.

This could probably be fixed by removing the ?? {} and ?? [] fallbacks entirely, or by guarding the template with emptiness checks.

What's the expected result?

No warning.

Link to Minimal Reproducible Example

decline

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: nice to haveNot breaking anything but nice to have (priority)good first issueGood for newcomers. If you need additional guidance, feel free to post in #dev on Discordregression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions