Skip to content

[app.config.ts] Could not resolve "virtual:app-config" #830

Closed

Description

@aklinker1

Discussed in #828

Originally posted by devjume July 19, 2024
Hi,

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

Activity

  1. moved this to In Progress in Aaron's Workon Jul 20, 2024
  2. aklinker1 commented on Jul 21, 2024

    @aklinker1
    MemberAuthor

    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

    pnpm i
    pnpm dev
  3. aklinker1 commented on Jul 21, 2024

    @aklinker1
    MemberAuthor

    OK, looks like the solution is to add the following vite config:

      vite: () => ({
        optimizeDeps: {
          exclude: ["virtual:app-config"],
        },
      }),

    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!

  4. moved this from In Progress to Done in Aaron's Workon Jul 21, 2024
  5. aklinker1 commented on Jul 21, 2024

    @aklinker1
    MemberAuthor

    Released in v0.18.15

  6. added theissue type on Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions