Skip to content

[v8] import.meta.glob array resolve fails in production build #22170

@CBx0-dev

Description

@CBx0-dev

Describe the bug

Description

In Vite 8, import.meta.glob fails to resolve patterns when using the Array syntax during a production build (vite build), though it works perfectly in development (vite dev).

When an array is passed to the glob, the production transformer fails to statically analyze the patterns, resulting in an empty object in the bundled output.

I tested it in both standard source files and virtual modules.

// src/services.ts
export const services = import.meta.glob([
    "/src/services/shared/**/*.service.ts",
    "/src/services/app-target/**/*.service.ts"
], { eager: true, import: "default" });

becomes

// dist/assets/index-XXXX.js
const services = /* @__PURE__ */ Object.assign({});

Expected behavior

The object should be populated with the resolved modules, matching the behavior of vite dev.

Workaround

Replacing the array with a single string literal resolves the issue, confirming that the parser is likely failing on the Array expression specifically.

Reproduction

https://stackblitz.com/edit/vitejs-vite-2odvphu7?terminal=dev

Steps to reproduce

Run npm run dev and open dev tools. The output after page load should look like the following:

Glob result: {/src/glob/pattern1/a.ts: 'Hello from A', /src/glob/pattern2/b.ts: 'Hello from B'}
[Normal Module]: Module at /src/glob/pattern1/a.ts says: Hello from A
[Normal Module]: Module at /src/glob/pattern2/b.ts says: Hello from B
Virtual services: {/src/glob/pattern3/c.ts: 'Hello from C', /src/glob/pattern4/d.ts: 'Hello from D'}
[Virtual Module]: Service at /src/glob/pattern3/c.ts says: Hello from C
[Virtual Module]: Service at /src/glob/pattern4/d.ts says: Hello from D

The shown behavior is right, both the normal and virtual import.meta.glob calls work.

But when running npm run build and npm run preview, the console output becomes:

Glob result: {}
Virtual services: {}

Which means that neither the normal nor the virtual module resolves the import.meta.glob correctly.
This can also be simply checked by looking at the output file:

//#region \0virtual:loader
var modules = /* @__PURE__ */ Object.assign({});
//#endregion


//...


//#region src/normal.ts
var modules$1 = /* @__PURE__ */ Object.assign({});
// ...
//#endregion

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor             
    Memory: 10.13 GB / 31.92 GB
  Binaries:
    Node: 24.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Users\kosch\AppData\Roaming\npm\yarn.CMD
    npm: 11.12.1 - C:\Users\kosch\AppData\Roaming\npm\npm.CMD
    pnpm: 10.29.3 - C:\Users\kosch\AppData\Local\pnpm\pnpm.CMD
    bun: 1.3.5 - C:\Users\kosch\.bun\bin\bun.EXE
  Browsers:
    Chrome: 146.0.7680.178
    Edge: Chromium (140.0.3485.54)
    Internet Explorer: 11.0.26100.7309
  npmPackages:
    vite: ^8.0.4 => 8.0.5

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions