Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive

fix(vite): respect ctx.nuxt.options.modulesDir for resolving externals with vite-node - #7612

Merged
pi0 merged 1 commit into
mainfrom
fix/vite-external
Sep 16, 2022
Merged

fix(vite): respect ctx.nuxt.options.modulesDir for resolving externals with vite-node#7612
pi0 merged 1 commit into
mainfrom
fix/vite-external

Conversation

@pi0

@pi0pi0 commented Sep 16, 2022

Copy link
Copy Markdown
Member

🔗 Linked issue

resolvesnuxt/nuxt#14952, nuxt/nuxt#14907, nuxt/nuxt#14802, nuxt/nuxt#14928

❓ 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)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

We are overriding shouldExternalize (PR: #6153) of vite-node, and use mlly resolver to directly resolve paths. Issue with nuxt/nuxt#14952 happens because directly setting URL to the directory of rootDir, causes resolving from parent node_modules and finally different resolved vue version. (Correct way is setting rootDir + '/_node_modules' or rootDir + /index.mjs)

This PR resolves issue by respecting modulesDir for resolving vue and other dependencies. In the future we might come of with better implementation to actually reuse same vite resolution. I didn't use return id on external branch (while it works!) until getting confirmation from @antfu. Vite-node's default external handler however does this. src

Also worth to mention that isExternal('vue') resolves to null as it is unable to determine external status.

📝 Checklist

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

@pi0
pi0 requested a review from antfuSeptember 16, 2022 22:11
@netlify

netlifyBot commented Sep 16, 2022

Copy link
Copy Markdown

Deploy Preview for nuxt3-docs canceled.

NameLink
🔨 Latest commitde1aa4e
🔍 Latest deploy loghttps://app.netlify.com/sites/nuxt3-docs/deploys/6324f491ff8ba60008ef15e6

const result = await isExternal(id)
if (result?.external) {
return resolveModule(result.id, { url: ctx.nuxt.options.rootDir })
return resolveModule(result.id, { url: ctx.nuxt.options.modulesDir })

@pi0pi0Sep 16, 2022

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

@antfu Shall we do this to be same as vite-node? Would it diretly require vue or let vite resolve to fullpath?

Suggested change
returnresolveModule(result.id,{url: ctx.nuxt.options.modulesDir})
returnid

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The id passed here should already be resolved by Vite. So yes I think we could directly do this.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for checking. FYI, it is not always resolved. You can reproduce it only with an external repository by putting a debugger. vue for instance is directly passed to shouldExternalize.

@pi0

pi0 commented Sep 16, 2022

Copy link
Copy Markdown
MemberAuthor

Merging as hotfix.

@pi0pi0 changed the title fix(vite): respect ctx.nuxt.options.modulesDir for resolving externalsfix(vite): respect ctx.nuxt.options.modulesDir for resolving externals with vite-nodeSep 16, 2022
@pi0
pi0 merged commit abd0feb into mainSep 16, 2022
@pi0
pi0 deleted the fix/vite-external branch September 16, 2022 22:29
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RC 9] [RC 10] Cannot read properties of undefined (reading 'modules') when vue is installed in parent dir

3 participants

@pi0@antfu@danielroe