Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset URLs prefixed with tilde (~/) in template are not resolving correctly when vite: true #989

Open
yckimura opened this issue Nov 27, 2023 · 1 comment
Labels
bug Something isn't working workaround available

Comments

@yckimura
Copy link

yckimura commented Nov 27, 2023

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: [email protected]
  • Builder: vite
  • User Config: bridge, serverHandlers, devServerHandlers, devServer, typescript, nitro, buildModules
  • Runtime Modules: -
  • Build Modules: (), @nuxt/[email protected]

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

@wattanx wattanx added the bug Something isn't working label Nov 28, 2023
@wattanx
Copy link
Collaborator

wattanx commented Dec 2, 2023

Until it is fixed, the following workarounds are available:

<script setup>
import assets from '~/assets/logo.svg'
</script>

<template>
  <div>
    <img :src="assets" width="100" height="100" />
  </div>
</template>
<template>
  <div>
    <img src="@/assets/logo.svg" width="100" height="100" />
  </div>
</template>

@yckimura yckimura changed the title Asset URLs in template are not resolving correctly when vite: true Asset URLs prefixed with tilde (~/) in template are not resolving correctly when vite: true Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working workaround available
Projects
None yet
Development

No branches or pull requests

2 participants