You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[app.config.ts] Could not resolve "virtual:app-config" #830
I am wondering what is correct way of using app.config.ts in wxt?
I am encountering error when using it in svelte component, but there is no error when using it in background.ts.
Problem:
// test.svelte - Doesn't work
<script lang="ts">
import { useAppConfig } from 'wxt/client';
console.log(useAppConfig());
</script>
Previous svelte component causes error:
Could not resolve "virtual:app-config"
node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/client.js:414:22:
414 │ import appConfig from "virtual:app-config";
You can mark the path "virtual:app-config" as external to exclude it from the bundle, which will
remove this error and leave the unresolved path in the bundle.
When I use it in background.ts it works just as stated in documentation.
// background.ts - Works
import { useAppConfig } from 'wxt/client';
console.log(useAppConfig());
Of course I can import defineAppConfig object in svelte as follows, which works. But is that correct way?
<script lang="ts">
import appConfig from '@/app.config';
console.log("appConfig", appConfig);
</script>
I am not familiar how app.config.ts is used in Nuxt. And Wxt docs didn't give any specific notes how to use it. Other than console.log(useAppConfig());.
wxt version: 0.18.14
I was wrong in my original response, it's not the dev server, it's the dependency optimization step from ESBuild that's throwing the error. Here's a full repro:
This tells ESBuild that the virtual:app-config module is external, and that esbuild shouldn't try and resolve the value. Then when vite tries to resolve it, the custom vite plugin used to resolve virtual modules finds the correct file.
I just need to add this to the default vite config, and we'll be good to go!
Activity
aklinker1 commentedon Jul 21, 2024
I was wrong in my original response, it's not the dev server, it's the dependency optimization step from ESBuild that's throwing the error. Here's a full repro:
repro.zip
aklinker1 commentedon Jul 21, 2024
OK, looks like the solution is to add the following vite config:
This tells ESBuild that the
virtual:app-configmodule is external, and that esbuild shouldn't try and resolve the value. Then when vite tries to resolve it, the custom vite plugin used to resolve virtual modules finds the correct file.I just need to add this to the default vite config, and we'll be good to go!
aklinker1 commentedon Jul 21, 2024
Released in
v0.18.15