Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

import.meta.glob expansion cannot be observed from user land plugin since 7.1.2 #373

Closed

Description

@hi-ogawa

Describe the bug

  • main.js
console.log(import.meta.glob('./repro.js'));
  • vite.config
    {
      name: 'debug',
      enforce: 'post',
      transform: {
        order: 'post',
        handler(code, id) {
          if (id.includes('/main.js')) {
            console.log('[transform:post]', { id, code });
          }
        },
      },
    },
  • log on 7.1.1
$ vite build
...
[transform:post] {
  id: '/home/projects/vitejs-rolldown-vite-mtmswjfm/src/main.js',
  code: 'import { __vitePreload } from "\x00vite/preload-helper.js";console.log(/* #__PURE__ */ Object.assign({"./repro.js": () => __vitePreload(() => import("./repro.js"),__VITE_IS_MODERN__?__VITE_PRELOAD__:void 0)}));\n' +
    '\n' +
    "document.querySelector('#app').innerHTML = `hello`;\n"
}
  • log on 7.1.2
$ vite build
...
[transform:post] {
  id: '/home/projects/vitejs-rolldown-vite-mtmswjfm/src/main.js',
  code: "console.log(import.meta.glob('./repro.js'));\n" +
    '\n' +
    "document.querySelector('#app').innerHTML = `\n" +
    '  <div>\n' +
    '    <h1>Hello Vite!</h1>\n' +
    '  </div>\n' +
    '`;\n'
}

My use case is to use "post" transform to strip away all the code but import so that it can traverse the entire module graph faster during rsc scan build.

https://github.com/vitejs/vite-plugin-react/blob/71bb49c7fe5c8362426d59ee8a99ea660b631b66/packages/plugin-rsc/src/plugin.ts#L904-L921

Reproduction

https://stackblitz.com/edit/vitejs-rolldown-vite-mtmswjfm?file=vite.config.ts

Steps to reproduce

  • run vite build on stackblitz

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    rolldown-vite:  7.1.2

Used Package Manager

npm

Logs

No response

Validations

Activity

  1. added theissue type on Aug 15, 2025
  2. hi-ogawa commented on Aug 15, 2025

    @hi-ogawa
    Author

    To be honest, I think I should fix this on rsc plugin side by keeping import.meta.glob during scan build, but if anyone has an idea, it's very welcome. Also I'm not sure if other plugins in the wild rely on the previous behavior.


    In the long run, rsc scan should be somehow reworked to not require extra dedicated build and that's partly the reason I don't mind adding a workaround on my end.

  3. shulaoda commented on Aug 15, 2025

    @shulaoda
    Member

    This might be because we enabled native plugins by default in version 7.1.2, and the native import-glob plugin runs via the transform_ast hook, which is a built-in hook in Rolldown. Since transform_ast always runs later than transform, its execution happens afterward.

  4. hi-ogawa commented on Aug 15, 2025

    @hi-ogawa
    Author

    My use case specifically is a bit weird one (and I have a workaround so not blocking vitejs/vite-plugin-react#721), but I think it was a nice property that user land post transform can observe all imports simply by es-module-lexer. It's possible that new behavior might confuse some other plugins.

    Since import.meta.glob shouldn't appear many times in the whole build, isn't it possible to change builtin implementation to use "regex code filter + extra parse/codegen" inside rust transform hook without performance hit?

  5. added
    feat: native plugins
    on Aug 18, 2025
  6. Razunter commented on Aug 19, 2025

    @Razunter

    Not sure if it's the same issue, but this import is ignored with rolldown-vite: import.meta.glob(['../assets/**', '../svgsprite/**/*.svg', '../icons/**/*.svg']), assets are missing in the manifest.json (using https://github.com/laravel/vite-plugin)

  7. hi-ogawa commented on Aug 20, 2025

    @hi-ogawa
    Author

    @Razunter Can you provide a reproduction?

  8. rayriffy commented on Aug 20, 2025

    @rayriffy

    I do have small repro here, I’m trying to debug import glob issue with native modules as well. Details and what I found already in README. but in which I think might related to vitejs#21947

    https://github.com/rayriffy/generouted-native-module-reproduction

  9. hi-ogawa commented on Aug 20, 2025

    @hi-ogawa
    Author
  10. Razunter commented on Aug 20, 2025

    @Razunter

    @Razunter Can you provide a reproduction?

    Can't reproduce on a small project and can't publish the large one...
    import.meta.glob(['../assets/**', '../svgsprite/**/*.svg', '../icons/**/*.svg']) fails, but wrapping it in console.log makes it work (in a broken way):

    console.log(import.meta.glob(['../assets/**', '../svgsprite/**/*.svg', '../icons/**/*.svg']))

    But *.svg gets transformed to *.js:

    "resources/sparkles/assets/logo-main.svg":{"file":"assets/logo-main-Di3hRtZh.js","name":"logo-main","src":"resources/sparkles/assets/logo-main.svg","isDynamicEntry":true,"assets":["assets/logo-main-8Z7lqjxw.svg"]}

    Previous manifest entry was

      "resources/sparkles/assets/logo-main.svg": {
        "file": "assets/logo-main-8Z7lqjxw.svg",
        "src": "resources/sparkles/assets/logo-main.svg"
      },

    TLDR: something weird, but probably unrelated to this issue.

  11. timotejroiko commented on Aug 28, 2025

    @timotejroiko

    I have a sveltekit project, and since updating a few packages my images no longer load, managed to narrow it down to this issue.

    Versions 7.1.1 and below work correctly, but 7.1.2 and above all fail to load my images.

    Relevant import.meta.glob call, i have tried multiple variations including removing everything except eager true, they all return an empty object.

        const sourcesDesktop = import.meta.glob(`$lib/assets/img/bg/Desktop-*`, {
            eager: true,
            query: { enhanced: true, w: '3840;3440;3072;2560;2208;1920;1536', format: 'webp;avif;jpg' },
            import: "default"
        });

    Relevant packages:

        "vite": "npm:rolldown-vite@7.1.5",
        "svelte": "5.38.6",
        "svelte-check": "4.3.1",
        "@sveltejs/adapter-node": "5.3.1",
        "@sveltejs/enhanced-img": "0.8.1",
        "@sveltejs/kit": "2.36.3",
        "@sveltejs/vite-plugin-svelte": "6.1.3",

    Is there anything i can do on my end to help troubleshoot this?

  12. shulaoda commented on Aug 28, 2025

    @shulaoda
    Member

    @timotejroiko You could try rolldown-vite@7.1.5 or set enableNativePlugins to false.

  13. ppjjzz commented on Sep 15, 2025

    @ppjjzz

    const modules = import.meta.glob<{ default: { view: LazyExoticComponent<() => JSX.Element> } }>(
    ['@@@/node_modules/xxx/*/app/web/router/.{js,jsx}', '@@@/plugin//app/web/router/*.{ts,tsx}'],
    { eager: true, exhaustive: true },
    );

    this code result different when i build the app since 7.1.2
    the file from node_modules can't be get

  14. shulaoda commented on Sep 15, 2025

    @shulaoda
    Member

    const modules = import.meta.glob<{ default: { view: LazyExoticComponent<() => JSX.Element> } }>( ['@@@/node_modules/xxx//app/web/router/.{js,jsx}', '@@@/plugin//app/web/router/.{ts,tsx}'], { eager: true, exhaustive: true }, );

    this code result different when i build the app since 7.1.2 the file from node_modules can't be get

    Do you mean the differences between enableNativePlugins: false and true, or the differences between different versions after enabling enableNativePlugins?

  15. DNA commented on Sep 26, 2025

    @DNA

    @Razunter @hi-ogawa I have the same problem, but I'm not sure if it's the same bug.

    What happens is that laravel-vite-plugin defines build.assetsInlineLimit to 0 so it can force all assets to be published no matter the size, but it seems that rolldown do not differentiate between assets and modules from import.meta.glob, so they get treeshaken.

    I got an workaround for this, but it generates a few unneeded JS files:

    const assets = import.meta.glob(['./images/**']);
    
    assets.forEach(() => {});
    $ vite build
    vite v7.1.7 building for production...
    ✓ 8 modules transformed.
    dist/index.html                  0.38 kB │ gzip: 0.26 kB
    dist/assets/img1-rUa6gnWw.svg    0.99 kB │ gzip: 0.60 kB 
    dist/assets/img2-DcBtz0py.svg    1.49 kB │ gzip: 0.77 kB
    dist/assets/img3-CtjI-TkI.svg   11.70 kB │ gzip: 0.69 kB
    dist/assets/img2-X2PTPcUM.js     0.05 kB │ gzip: 0.07 kB => var e=`/assets/img2-DcBtz0py.svg`;export{e as default};
    dist/assets/img3-CwHAmnyL.js     0.06 kB │ gzip: 0.07 kB => var e=`/assets/img3-CtjI-TkI.svg`;export{e as default};
    dist/assets/img1-DgYHKw1V.js     0.06 kB │ gzip: 0.08 kB => var e=`/assets/img1-rUa6gnWw.svg`;export{e as default};
    dist/assets/index-Ba_HH61w.js    2.15 kB │ gzip: 1.06 kB
    ✨  Done in 7.40s.
    

    I have also been able to reproduce it on stackblits:
    https://stackblitz.com/edit/vitejs-vite-mvgpmagk?file=README

  16. self-assigned this
    on Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feat: native pluginspending triage

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions