Skip to content

Non-intuitive side-effects when using import.meta.glob with eager #21924

Description

@Janpot

Describe the bug

When using import.meta.glob with eager: true it appears that the imports it generates are prepended to the current module imports, this causes side-effects to be executed in a non-intuitive order. (As per mui/base-ui#4370).

Reproduction

https://github.com/Janpot/vite-glob-side-effects-repro

Steps to reproduce

// ./a.ts
console.log('hello from a');
export {}

// ./b.ts
console.log('hello from b');
export {}

// ./main.ts
import './a';

const mods = import.meta.glob('./b.ts', { eager: true })

prints

hello from b
hello from a

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M1
    Memory: 107.45 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.11.1 - /Users/janpotoms/.nvm/versions/node/v24.11.1/bin/node
    npm: 11.6.2 - /Users/janpotoms/.nvm/versions/node/v24.11.1/bin/npm
    pnpm: 10.13.1 - /Users/janpotoms/.nvm/versions/node/v24.11.1/bin/pnpm
  Browsers:
    Safari: 17.6
  npmPackages:
    @vitejs/plugin-react: ^6.0.1 => 6.0.1 
    vite: ^8.0.0 => 8.0.0

Used Package Manager

pnpm

Logs

No response

Validations

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

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions