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

Issues importing modules with virtual: in the name #19391

Closed
7 tasks done
mchugh19 opened this issue Feb 9, 2025 · 1 comment
Closed
7 tasks done

Issues importing modules with virtual: in the name #19391

mchugh19 opened this issue Feb 9, 2025 · 1 comment

Comments

@mchugh19
Copy link

mchugh19 commented Feb 9, 2025

Describe the bug

If I try to use https://github.com/russss/vite-plugin-render-svg within my vite config import { manifest } from 'virtual:render-svg'; to dynamically pass along image names, the build process throws an error:

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'virtual:'

Any ideas?

Thanks!

Reproduction

https://github.com/mchugh19/zabbix-vue/tree/mv3-2

Steps to reproduce

vite build where vite.config.js contains import { manifest } from 'virtual:render-svg';

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (16) x64 AMD Ryzen 9 5900HX with Radeon Graphics
    Memory: 4.99 GB / 7.47 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 23.7.0 - ~/.nvm/versions/node/v23.7.0/bin/node
    Yarn: 1.22.22 - ~/.yarn/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v23.7.0/bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^4.5.0 => 4.6.2 
    vite: ^5.0.0 => 5.4.14

Used Package Manager

npm

Logs

Click to expand!
failed to load config from /home/xian/tech/gits/zabbix-vue/vite.config.js
error during build:
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'virtual:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:208:11)
    at defaultLoad (node:internal/modules/esm/load:103:3)
    at ModuleLoader.load (node:internal/modules/esm/loader:739:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:519:43)
    at #createModuleJob (node:internal/modules/esm/loader:543:36)
    at #getJobFromResolveResult (node:internal/modules/esm/loader:312:34)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:280:41)

Validations

@hi-ogawa
Copy link
Collaborator

Vite config itself cannot be processed by Vite plugins since that's where plugins are defined, so virtual:render-svg does't work there. See also https://vite.dev/config.

By default, Vite uses esbuild to bundle the config into a temporary file and load it.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2025
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

2 participants