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

[vite/plugin] The "attributes" property of ModuleInfo is not supported. #15411

Open
7 tasks done
vdegenne opened this issue Dec 22, 2023 · 4 comments
Open
7 tasks done

Comments

@vdegenne
Copy link

vdegenne commented Dec 22, 2023

Describe the bug

When using this.getModuleInfo(id).attributes in a plugin (for instance in transform hook) the following error occurs :

[vite] The "attributes" property of ModuleInfo is not supported.

But the same code works in native Rollup plugins.

related issue: Support for moduleInfo.meta in resolveId hook still not equivalent in vite dev and vite build

Reproduction

https://stackblitz.com/edit/vitejs-vite-5et2xu?file=vite.config.js&terminal=dev

System Info

System:
    OS: Linux 6.5 Fedora Linux 37 (Workstation Edition)
    CPU: (16) x64 AMD Ryzen 9 5900HS with Radeon Graphics
    Memory: 6.49 GB / 15.02 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0 - /usr/local/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.3.0 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 120.0.6099.109
  npmPackages:
    vite: ^5.0.10 => 5.0.10

Used Package Manager

npm

Logs

Click to expand!
10:46:44 PM [vite] Internal server error: [vite] The "attributes" property of ModuleInfo is not supported.

Validations

Copy link

stackblitz bot commented Dec 22, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@Kycermann
Copy link

Kycermann commented May 7, 2024

This is breaking rollup-plugin-import-css-classes when running on Vite.

@jantimon
Copy link

jantimon commented Jul 23, 2024

I created a package which currently supports only webpack but I would love to add support for Vite too.

Unfortunately I get The "code" property of ModuleInfo is not supported. during vite dev:

`[vite] The "${key}" property of ModuleInfo is not supported.`,

The information I need is available but only behind a private api (this._container.moduleGraph.idToModuleMap.get(id).transformResult.code)

With Webpack it is possible during dev and build https://webpack.js.org/api/loaders/#thisloadmodule to access the code and attributes of other modules

Is there anything I can do to support adding this feature?

@swwind
Copy link

swwind commented Aug 8, 2024

It appears that the return value of this.load differs between serve and build modes.

In serve mode, the moduleInfo object only contains the id and meta properties, as seen in these lines:

module.info = new Proxy(
{ id, meta: module.meta || EMPTY_OBJECT } as ModuleInfo,

While we can manually obtain a ModuleNode object using this._container.moduleGraph.getModuleById(id), the transformResult remains null. This suggests that the module might not have been loaded or transformed at all.

In build mode, everything just works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants