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

exclude also default resolved Vite virtual modules #22833

Closed
userquin opened this issue Aug 26, 2023 · 1 comment · Fixed by #22834
Closed

exclude also default resolved Vite virtual modules #22833

userquin opened this issue Aug 26, 2023 · 1 comment · Fixed by #22834

Comments

@userquin
Copy link
Member

Environment

Nuxt project info:                                                                                                                                                        13:07:25

------------------------------
- Operating System: Windows_NT
- Node Version:     v18.16.0
- Nuxt Version:     3.7.0
- CLI Version:      3.7.0
- Nitro Version:    2.6.1
- Package Manager:  pnpm@8.6.12
- Builder:          -
- User Config:      -
- Runtime Modules:  -
- Build Modules:    -
------------------------------

Reproduction

Open the following SB repo using virtual:pwa-info:
https://stackblitz.com/edit/nuxt-starter-dnvrut?file=app.vue,package.json,nuxt.config.ts

Once Nuxt starts, there is a warning about resolving virtual:pwa-info (should be \0virtual:pwa-info):
imagen

You can also reproduce it in the nuxt repo using the playground , just add this to the playground nuxt.config.ts file:

const virtual = 'virtual:xxx'
const resolvedVirtual = `\0${virtual}`

export default defineNuxtConfig({
  vite: {
    plugins: [{
      name: 'xxx',
      enforce: 'post',
      resolveId (id) {
        if (id === virtual) {
          console.log('xxx:resolveId', id, resolvedVirtual)
          return resolvedVirtual
        }
      },
      load (id) {
        if (id === resolvedVirtual) {
          console.log('xxx:load', id, resolvedVirtual)
          return 'export const xxx = "xxx";'
        }
      }
    }]
  }
})

Add this component on playground folder:

import { defineComponent } from 'vue'
import { xxx } from 'virtual:xxx'

export default defineComponent({
  setup () {
    if (xxx) {
      console.log(xxx)
    }

    return () => null
  }
})

And add the component to the app.vue:

<script setup lang="ts">
import VirtualComponent from './VirtualComponent'
</script>

<template>
  <VirtualComponent />
  <!-- Edit this file to play around with Nuxt but never commit changes! -->
  <div>
    Nuxt 3 Playground
  </div>
</template>

<style scoped>

</style>

You will see the warning once Nuxt starts:

[nuxt] Could not resolve id virtual:xxx D:\work\projects\userquin\GitHub\userquin\nuxt-org\nuxt\playground\index.html

Describe the bug

Resolved Vite virtual modules should be also excluded, \0virtual: should also be excluded: https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention.

There are a few modules only checking for virtual: prefix, we should also review the usage:

imagen

I'm preparing a PR.

Additional context

No response

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant