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

Vue is externalized no matter the ssr.noExternal value #9117

Closed
7 tasks done
paraboul opened this issue Jul 14, 2022 · 4 comments · Fixed by #9128
Closed
7 tasks done

Vue is externalized no matter the ssr.noExternal value #9117

paraboul opened this issue Jul 14, 2022 · 4 comments · Fixed by #9128

Comments

@paraboul
Copy link
Contributor

Describe the bug

I'm migrating a project from vite 2 to 3, and just facing a little issue with SSR externals.

It vite 2, I was just using something like noExternal: /./ to make sure nothing is externalised, which worked well.

In Vite 3, it seems that vue and @vue/server-renderer are not externalised (the generated output imports vue methods from the vue package). All others deps are bundled into the mjs output.

I tried to set ssr.noExternal to true, but then I got various error like Cannot bundle Node.js built-in "http" imported from "node_modules/axios/lib/adapters/http.js". Consider disabling ssr.noExternal or remove the built-in dependency

I also tried to manually exclude 'vue' package with something like noExternal: [/./, 'vue'] with no luck

Another weird thing is that the import output looks broken too. I tried to add vue as a deps as a workaround but got this

import require$$0$1, { defineComponent, onBeforeUnmount, watchEffect, ref as ref$1, inject, reactive as reactive$1, computed as computed$1, markRaw, mergeProps, unref, createVNode, resolveDynamicComponent, useSSRContext, openBlock, createElementBlock, createElementVNode, watch, onActivated, onMounted, shallowRef, resolveComponent, withCtx, createBlock, toDisplayString, createTextVNode, createCommentVNode, getCurrentInstance, h as h$4, isRef as isRef$1, readonly as readonly$1, onBeforeUpdate, onErrorCaptured, Suspense, nextTick, createSSRApp, createApp as createApp$1, createStaticVNode, onUnmounted, toRef, Fragment, renderList, withModifiers, renderSlot, defineAsyncComponent, useSlots, withDirectives, vModelText, vShow, provide, withAsyncContext, resolveDirective, cloneVNode, Teleport, toRaw as toRaw$1, Transition, triggerRef, TransitionGroup, effectScope } from "vue";
       ^^^^^^^^^^^^
SyntaxError: The requested module 'vue' does not provide an export named 'default'

Reproduction

https://stackblitz.com/edit/vitejs-vite-7k3ode?file=dist/server/entry-server.js

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 647.03 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.5.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.12.1 - /usr/local/bin/npm

Used Package Manager

yarn

Logs

No response

Validations

@ydcjeff
Copy link
Contributor

ydcjeff commented Jul 14, 2022

It worked with extra plugin mutating config.ssr.external tho. repro link

@paraboul
Copy link
Contributor Author

It worked with extra plugin mutating config.ssr.external tho. repro link

Indeed, thanks 👍. This feels a bit hackish though. Is there any particular reason that Vue won't be externalised despite the ssr.noExternal rule?

@ydcjeff
Copy link
Contributor

ydcjeff commented Jul 14, 2022

I think Vite checks external first then noExternal, not sure how this should be properly handled?

if (ssr.external?.includes(id)) {
return true
}
if (typeof noExternal === 'boolean') {
return !noExternal
}
if (noExternalFilter && !noExternalFilter(id)) {
return false

@sapphi-red
Copy link
Member

I think this part is affecting this. Since vite 3 externalizes everything, maybe this should be removed.

ssr: {
external: ['vue', '@vue/server-renderer']
}

@github-actions github-actions bot locked and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants