-
-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(nuxt): do not apply import protection to top-level resolution #7344
Conversation
β Deploy Preview for nuxt3-docs canceled.
|
Thanks! This defenitly reduces some frustrations but why should a plugin attempt to import from |
I am not sure exactly how to answer that. Tailwind on its own is triggering this import protection rule. (ie. I'm reproducing it with pure tailwind, not the nuxt integration). note: the import protection rule triggers on resolving an id, not on importing from it. |
I understand issue with our impl and tailwind but the change of this PR is also defusing the import protection for |
What about marking triggered resolutions ( |
What makes you say they can import in |
It won't work because there is another import protection rule for |
Just did a quick test to confirm (thought I had done it when creating PR but always worth checking!) and indeed import protection works correctly in You can confirm with: <script setup lang="ts">
import config from '~/nuxt.config'
console.log({ config })
</script>
<template>
<!-- Edit this file to play around with Nuxt but never commit changes! -->
<div>
Nuxt 3 Playground
</div>
</template>
<style scoped>
</style>
(The reason I asked is because I was wondering if you had done some testing to make you think the protection wasn't still working properly. If so, a reproduction would be helpful.) |
nuxt.config: export const a = 123
export default {} app.vue: <script setup lang="ts">
import { a } from '~/nuxt.config'
console.log(a)
</script> (works with no warning) |
That's not caused by this PR - it's a bug with the import protection rules. Pushing fix. To show that imports from <script setup lang="ts">
import { useNuxtApp } from 'nuxt/app'
console.log({ useNuxtApp })
</script> |
Before your last commit, protection works without change to exclude top level |
I think so. π Will have a look. |
π Linked issue
resolves nuxt/nuxt#13278
β Type of change
π Description
We can avoid triggering import protection from a top-level
this.resolve
call (i.e. within another vite plugin), as there may be valid use cases for this, like tailwind resolving the nuxt.config file.Relevant vite section:
https://github.com/vitejs/vite/blob/757a92f1c7c4fa961ed963edd245df77382dfde6/packages/vite/src/node/server/pluginContainer.ts#L562-L566
π Checklist