Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling getModuleInfo doesn't return custom module meta data in load hook #3240

Closed
mattcompiles opened this issue May 3, 2021 · 2 comments
Closed

Comments

@mattcompiles
Copy link
Contributor

mattcompiles commented May 3, 2021

Describe the bug

Calling this.getModuleInfo inside load returns no information. My scenario is forwarding custom module meta data from the resolveId hook and then trying to access it within the load hook. Reading through the Rollup plugin API docs I would expect the following code to work.

const testPlugin = {
  name: 'module-info',
  resolveId(id) {
    if (id === 'virtual-file') {
      return { id, meta: { moduleInfo: { canYouSeeMe: true } } };
    }
  },
  load(id) {
    if (id === 'virtual-file') {
      const { meta } = this.getModuleInfo(id);
      
      if (meta.moduleInfo.canYouSeeMe) {
        // do stuff
      }
    }
  },
};

Reproduction

https://github.com/mattcompiles/vite-moduleinfo-issue/blob/main/vite.config.js

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 1.03 GB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.18.2 - ~/.volta/tools/image/node/12.18.2/bin/node
    Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
    npm: 6.14.5 - ~/.volta/tools/image/node/12.18.2/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 90.0.4430.93
    Firefox: 82.0.3
    Safari: 12.1.2
  npmPackages:
    vite: ^2.2.3 => 2.2.3 

Used package manager: yarn

@Niputi
Copy link
Contributor

Niputi commented Nov 9, 2021

related pr #5465

@Niputi
Copy link
Contributor

Niputi commented Nov 19, 2021

from vite 2.7 beta 4

import { defineConfig } from "vite";

export default defineConfig({
  plugins: [{
    name: 'module-info',
    resolveId(id) {
      if (id === 'virtual-file') {
        console.log("meta0", (this.getModuleInfo(id)));
        return { id, meta: { moduleInfo: { canYouSeeMe: true } } }
      }
    },
    load(id) {
      if (id === 'virtual-file') {
        console.log("meta1", (this.getModuleInfo(id)));
        // load code is needed to see meta data added
        return { code: ''}
      }
    }
  }]
})

outputs

meta0 null
meta0 null
meta0 null
meta1 null
meta0 null
meta0 { id: 'virtual-file', meta: { moduleInfo: { canYouSeeMe: true } } }
meta0 { id: 'virtual-file', meta: { moduleInfo: { canYouSeeMe: true } } }

@Niputi Niputi closed this as completed Nov 19, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants