Uh oh!
There was an error while loading. Please reload this page.
fix(nuxt): do not apply import protection to top-level resolution - #7344
Conversation
✅ Deploy Preview for nuxt3-docs canceled.
|
pi0
commented
Sep 8, 2022
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. |
pi0
commented
Sep 10, 2022
I understand issue with our impl and tailwind but the change of this PR is also defusing the import protection for |
pi0
commented
Sep 10, 2022
What about marking triggered resolutions ( |
danielroe
commented
Sep 10, 2022
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">importconfigfrom'~/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: exportconsta=123exportdefault{}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 |
danielroe
commented
Sep 10, 2022
I think so. 👍 Will have a look. |
🔗 Linked issue
resolvesnuxt/nuxt#13278
❓ Type of change
📚 Description
We can avoid triggering import protection from a top-level
this.resolvecall (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