Skip to content

[Bug]: VirtualModulesPlugin writeModule example seems wrong. #11599

@TheOnlyArtz

Description

@TheOnlyArtz

System Info

System:
OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13800H
Memory: 21.48 GB / 30.98 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.16.0 - ~/.nvm/versions/node/v22.16.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.16.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v22.16.0/bin/npm
bun: 1.2.21 - /snap/bin/bun

Details

Simplified code:

import { defineConfig, rspack } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
const virtualModulesPlugin = new rspack.experiments.VirtualModulesPlugin();

export default defineConfig({
  plugins: [pluginReact()],
  tools: {
    rspack: {
      plugins: [
        virtualModulesPlugin,
        {
          apply(compiler: any) {
            compiler.hooks.beforeCompile.tap('MyPlugin', () => {
              // Dynamically create virtual modules
              const moduleContent = 'export const ErrorHighIcon = 15;';
              virtualModulesPlugin.writeModule(
                'node_modules/@tsgs/react-iconss',
                moduleContent,
              );
            });
          },
        },
      ],
    },
  },
  source: {
    entry: {
      index: './src/index.tsx',
    },
  },
});

This example is straight from the Docs of the new VirtualModulesPlugin
Running this results in a crash stating Virtual file system has not been initialized seems like the right hook to use make other than beforeCompile !

Reproduce link

No response

Reproduce Steps

run a simple rspack project with this config.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions