@rollup/plugin-virtual does not work
See original GitHub issueOpening 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
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!
Note: only the null byte needed to be fixed. The
src/robin.js
fails simply becauserobin.js
isn’t actually inside asrc
directory.