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

rollup-plugin-multi-entry (virtual) does not work with dev server #11413

Open
7 tasks done
Natureshadow opened this issue Dec 18, 2022 · 5 comments
Open
7 tasks done

rollup-plugin-multi-entry (virtual) does not work with dev server #11413

Natureshadow opened this issue Dec 18, 2022 · 5 comments

Comments

@Natureshadow
Copy link

Describe the bug

We have a Vite project that must pull together code from several entry scripts into one entry chunk, and are using rollup-plugin-multi-entry to achieve this. That in turn uses rollup-plugin-virtual.

Vite config:

const fs = require("fs");
const path = require("path");

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue2";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import graphql from "@rollup/plugin-graphql";
import multi from '@rollup/plugin-multi-entry';

export default defineConfig({
  base: "/static",
  build: {
    outDir: path.resolve("./vite_bundles/"),
    manifest: true,
    rollupOptions: {
      input: ["aleksis/core/assets/index.js", "aleksis/core/assets/foo.js"],
    },
  },
  server: {
    strictPort: true,
    origin: "http://127.0.0.1:5173",
  },
  plugins: [
    multi({entryFileName: "aleksis-local-full.js"}),
    vue(),
    nodeResolve({ modulePaths: [path.resolve("./node_modules")] }),
    graphql(),
  ],
  resolve: {
    alias: {
      vue: "vue/dist/vue.esm.js",
    },
  },
});

Now, when building for production, this generates the following manifest snippet:

  "virtual:aleksis-local-full.js": {
    "file": "aleksis-local-full.js",
    "src": "virtual:aleksis-local-full.js",
    "isEntry": true,
    "css": [
      "assets/_virtual_aleksis-local-full-807696e7.css"
    ],
    "assets": [
      "assets/materialdesignicons-webfont-5be9e9d7.eot",
      "assets/materialdesignicons-webfont-633d596f.woff2",
      "assets/materialdesignicons-webfont-7f3afe9b.woff",
      "assets/materialdesignicons-webfont-948fce52.ttf"
    ]
  },
  "\u0000virtual:aleksis-local-full.css": {
    "file": "assets/_virtual_aleksis-local-full-807696e7.css",
    "src": "\u0000virtual:aleksis-local-full.css"
  }

Note how one is prefixed with only virtual and one with \u000virtual. This is strange, but in production, it works.

When running the dev server, however, it fails to resolve /static/virtual:aleksis-local-full.js and throws a 404 error.

My current guess is that rollup-plugin-virtual always expects the \0virtual prefix including the NULL byte, and thus, in the dev server, resolving the bundle name without the NULL byte fails. So the issue here would be that some code parts include the NULL byte and some don't.

Reproduction

https://github.com/Natureshadow/vite-multi-mwe

Steps to reproduce

Run npm install and npm run dev, then try to access http://localhost:5173/virtual:multi-entry.js.

System Info

System:
    OS: Linux 6.0 Debian GNU/Linux bookworm/sid
    CPU: (8) x64 Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
    Memory: 8.85 GB / 15.26 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.12.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.2.0 - /usr/bin/npm
  Browsers:
    Chromium: 108.0.5359.124
    Firefox: 108.0
  npmPackages:
    vite: ^4.0.0 => 4.0.2

Used Package Manager

npm

Logs

No response

Validations

@Natureshadow
Copy link
Author

OK, so, manifest generation strips off the NULL character for all bundles: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/manifest.ts#L45

And it seems to be intended that when using the dev server, the NULL character must be passed in the URL as well (how strange is that)?

So the problem boils down to the expected bundle names discovered from the manifest and expected by the dev server are asymmetric.

@bluwy
Copy link
Member

bluwy commented Nov 10, 2023

Related: #6225

@frederikbosch
Copy link

@Natureshadow were you able to somehow access virtual files with the dev server?

@Natureshadow
Copy link
Author

Natureshadow commented Jan 9, 2024 via email

@hansegucker
Copy link

@hansegucker do you know how this ended up?

I also don't remember right away. I will have to take another look.

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

4 participants