nuxt / vite

⚡ Vite Experience with Nuxt 2
https://vite.nuxtjs.org
1.38k stars 46 forks source link

Failed to resolve async components, failure in references to `static` folder #109

Open Tahul opened 3 years ago

Tahul commented 3 years ago

Versions

nuxt-vite: 0.0.36 nuxt: 2.16.0-26932357.0a988668 (nuxt-edge)

Reproduction

https://codesandbox.io/s/nifty-jones-p9kqf?file=/components/Logo.vue

Description

Had an issue with SVG imports from tags, tried to resolve it using:

vite: {
    publicDir: resolve(__dirname, 'static')
  }

Fixed the imports, but I still have failures to resolve components, marked by these error messages:

[Vue warn]: Failed to resolve async component: () => import('/@fs/Users/tahul/Projets/nuxt/nuxtjs.com/components/templates/Home/HomeDiscover.vue').then(c => c.default || c)
Reason: TypeError: Failed to fetch dynamically imported module: http://localhost:3000/@fs/Users/tahul/Projets/nuxt/nuxtjs.com/components/templates/Home/HomeDiscover.vue

I don't know if this is an issue or just a misconfiguration from my side, we investigated with @farnabaz but couldn't find the source of this problem.

Also tried installing @nuxt/components just to be sure it wasn't a problem from that side and it didn't solved the problem.

Thank you a lot for your help, amazing work on nuxt-vite, can't wait to use it on this project. 🚀

Tahul commented 3 years ago

I've updated the reproduction to a CodeSandbox example.

You can visit it here.

Tahul commented 3 years ago

The problem seem to happen when the src attribute from an image is used to point to an image directly:

<img src="/img/test.svg" />

^ This seem to be throwing an error.

<template>
  <img :src="src" />
</template>

<script>
export default {
  setup() {
    return {
      src: '/img/test.svg'
    }
  }
}
</script>

^ This seem to work.

Tahul commented 3 years ago

I fixed it temporarily on my repository by doing that:

<img src="~/static/img/test.svg" />

I think this is a bug, or at least an update in the behavior that needs to be document on nuxt-vite docs.

pi0 commented 3 years ago

Hi dear @Tahul. Indeed this is related to #7. I think at the moment using nuxt-vite is safe by disabling ssr.

PR welcome to update this in readme checklist.

Tahul commented 3 years ago

@pi0 ; https://github.com/nuxt/vite/pull/111

Here is a PR including explanations to work around this issue until this is fixed.

I added it to the "Common issues" section of nuxt-vite documentation.