question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@rollup/plugin-virtual does not work

See original GitHub issue

Opening this issue as an enhancement following the relabelling of https://github.com/vitejs/vite/issues/1428

Is your feature request related to a problem? Please describe.

@rollup/plugin-virtual is currently not working. Checking the implementation, it looks like it may be workable.

I create a repro for this issue starting from the vanilla create app: https://github.com/matias-capeletto/vite-rollup-plugin-virtual

It is using the example from the plugin docs (batman and robin are from there) I am also using it with { enforce: 'pre', plugin } so it is applied before the rest of vite core plugins:

  plugins: [
    {
      enforce: 'pre', ...virtual({
        batman: `export default 'na na na na na'`,
        'src/robin.js': `export default 'batmannnnn'`
      })
    },
  ]

Additional context

It looks like there are two unrelated issues. Vite doesn’t like the

import robin from "./robin.js";
$ vite build
building for production...
Could not resolve './robin.js' from main.js
error during build:
Error: Could not resolve './robin.js' from main.js

When removing this line, the other virtual file also fails. I think it is related to the prefix used by the plugin

const PREFIX = `\0virtual:`;

In Dev the error reads:

Uncaught TypeError: Failed to resolve module specifier "/@id/

During build it correctly compiles and runs through.

System Info

vite version: 2.0.0-beta.19 Operating System: Windows 10 Home, 10.0.18363 N/A Build 18363 Node version: v15.5.0 Package manager and version: yarn v1.22.10

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kaseccommented, Jan 17, 2021

Ok, thank you buddy, I really misunderstood about how to implement it, and yesterday before my comment https://vite-rollup-plugins.patak.dev had not the implementation code in virtual-code.

Excellent job!

1reaction
yyx990803commented, Jan 11, 2021

Note: only the null byte needed to be fixed. The src/robin.js fails simply because robin.js isn’t actually inside a src directory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@rollup/plugin-virtual - npm
Start using @rollup/plugin-virtual in your project by running `npm i @rollup/plugin-virtual`. There are 102 other projects in the npm ...
Read more >
rollup-plugin-virtual examples - CodeSandbox
Learn how to use rollup-plugin-virtual by viewing and forking rollup-plugin-virtual example apps on CodeSandbox.
Read more >
rollup-plugin-virtual | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Plugin API | Vite (main branch)
If the plugin doesn't use Vite specific hooks and can be implemented as a ... Virtual modules in Vite (and Rollup) are prefixed...
Read more >
Simulate multiple domains with rollup-plugin-dev
One way to solve this problem for development is to serve up your widget on some port and then create a separate project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found