Skip to content

SSR transform loses Object.defineProperty in certain cases #7365

@Conduitry

Description

@Conduitry

Describe the bug

When running a module like

import { foo } from '$lib/things.js';

export const get = () => foo // no semicolon

through Vite's SSR transform, I end up with

const __vite_ssr_import_0__ = await __vite_ssr_import__("/src/lib/things.js");

const get = () => __vite_ssr_import_0__.foo

rather than the correct

const __vite_ssr_import_0__ = await __vite_ssr_import__("/src/lib/things.js");

const get = () => foo
Object.defineProperty(__vite_ssr_exports__, "get", { enumerable: true, configurable: true, get(){ return get }});

As far as I can tell, defineExport is getting called correctly, and it is adding the appropriate Object.defineProperty call, but the magic-string call at

s.overwrite(id.start, id.end, binding)
is removing it again.

Reproduction

https://github.com/Conduitry-Repros/vite-7365

System Info

  System:
    OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 9.80 GB / 12.32 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Yarn: 1.22.15
    npm: 8.5.2

Used Package Manager

pnpm

Logs

n/a

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions