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

fix(nuxt, vite): do not use cjs utils to resolve/alias vue #21837

Merged
merged 4 commits into from
Jun 28, 2023

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

#14146

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Vite and Nitro correctly resolve vue dependencies, and it is far better to defer resolution to the bundlers than override it ourselves, particularly with support for non-hoist:

You can test with this plugin:

Details
const logger = {
  name: 'log',
  writeBundle (_options, bundle) {
    for (const file in bundle) {
      const chunk = bundle[file]
      if (chunk.type === 'asset') { continue }
      const resolvedVueFiles = chunk?.moduleIds.filter(i => i.includes('vue'))
      if (resolvedVueFiles?.length) {
        console.log(resolvedVueFiles)
      }
    }
  }
}

export default defineNuxtConfig({
  experimental: {
    // you can try with and without
    externalVue: false
  },
  nitro: {
    rollupConfig: {
      plugins: [logger]
    }
  },
  vite: {
    plugins: [logger]
  }
})

(In my testing, before this PR, with externalVue: false vue was actually being bundled twice in nitro bundle.)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Jun 28, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if you have already tested it against latest nitro.

We had to get rid of this workaround sooner or later.

Also linking to unjs/nitro#1118 which might be needed to dedup external vue

@danielroe
Copy link
Member Author

I've tested it in the framework repo here. Are there module resolution changes coming upstream from nitro?

@pi0
Copy link
Member

pi0 commented Jun 28, 2023

Are there module resolution changes coming upstream from nitro?

Only that we might start to apply runtime-keys worker conditions to worker targets which i don't think Vue is having them and should be fine..

@danielroe danielroe changed the title fix(nuxt, vite): do not use cjs utils to resolve and alias vue libraries fix(nuxt, vite): do not use cjs utils to resolve/alias vue Jun 28, 2023
@danielroe danielroe merged commit e023c06 into main Jun 28, 2023
28 checks passed
@danielroe danielroe deleted the fix/vite-resolve branch June 28, 2023 13:49
@github-actions github-actions bot mentioned this pull request Jun 28, 2023
@sei-jdshimkoski
Copy link

I think this might have broken this particular Nuxt Config setting (Nuxt 3.6.2 with Nitro 2.5.2):

vite: {
    build: {
      rollupOptions: {
        output: {
          manualChunks(_id) {
            return 'index'
          }
        },
      },
    },
  },

I now get a bunch of <BLAH> cannot be included in manualChunks because it is resolved as an external module by the "external" option or plugins.

@danielroe
Copy link
Member Author

@sei-jdshimkoski Maybe you you could open an issue with reproduction? I don't have an issue with that code in a minimal sandbox.

@wtagain
Copy link

wtagain commented Jul 13, 2023

I think this might have broken this particular Nuxt Config setting (Nuxt 3.6.2 with Nitro 2.5.2):

vite: {
    build: {
      rollupOptions: {
        output: {
          manualChunks(_id) {
            return 'index'
          }
        },
      },
    },
  },

I now get a bunch of <BLAH> cannot be included in manualChunks because it is resolved as an external module by the "external" option or plugins.

Same question. Did you fix it?

@sei-jdshimkoski
Copy link

Sorry, was out of town and away from my computer. I'll try to open an issue with reproduction today.

@sei-jdshimkoski
Copy link

Ticket is here: #22127

@sei-jdshimkoski
Copy link

The only change in that minimal reproduction is the vite manualChunks setting in the nuxt config file.

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

Successfully merging this pull request may close these issues.

None yet

4 participants