Asset URLs prefixed with tilde (`~/`) in template are not resolving correctly when `vite: true`
Open
Nobody has claimed this yet.
bug
workaround available
- Dominant language
- TypeScript
- Stars
- 285
- Forks
- 33
- Avg merge
- 22h 38m
- Merged PRs (30d)
- 3
Description
Environment
- Operating System: Linux
- Node Version: v18.18.0
- Nuxt Version: 2.17.2
- CLI Version: 3.9.1
- Nitro Version: 2.8.0
- Package Manager: npm@9.4.2
- Builder: vite
- User Config: bridge, serverHandlers, devServerHandlers, devServer, typescript, nitro, buildModules
- Runtime Modules: -
- Build Modules: (),
@nuxt/bridge@3.0.0-rc.3-28343365.3c40b3f
Reproduction
https://stackblitz.com/edit/nuxt-starter-abfxvv
Describe the bug
Asset urls prefixed with tilde (~/) in template are not resolving correctly when building with vite: true.
- Expected:
/_nuxt/assets/logo.svg - Actual:
/_nuxt/pages/assets/logo.svg
nuxt.config.js:
import { defineNuxtConfig } from '@nuxt/bridge';
export default defineNuxtConfig({
bridge: {
vite: true,
},
});
pages/index.vue:
<template>
<div>
<img src="~/assets/logo.svg" width="100" height="100" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({});
</script>
Output:
<div id="__layout">
<div>
<img src="/_nuxt/pages/assets/logo.svg" width="100" height="100">
</div>
</div>
Additional context
No response
Logs
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the StackBlitz reproduction, then inspect the handling of the ~/assets/logo.svg reference from pages/index.vue when bridge.vite is enabled. Compare the generated URL with the expected /_nuxt/assets/logo.svg; done means the template produces that URL under the reported Nuxt, Bridge, and Vite configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxtjs, typescript, vite
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100