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

feat!: remove ssr proxy for externalized modules #14521

Merged
merged 10 commits into from
Oct 19, 2023
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Oct 3, 2023

Description

Implements solution 2 of #14503

SSR-externalized module are now not handled with special .default and .__esModule handling access in dev, matching the behaviour in prod. Non-externalized modules stay the same, they are already ESM after all.

The main change is to not call proxyESM. The rest are created for better error messages to identify how to fix it.

I also added legacy.proxySsrExternalModules to return to the previous behaviour.

Additional context

See #14503 for more context.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy added feat: ssr breaking change p3-significant High priority enhancement (priority) labels Oct 3, 2023
Copy link
Collaborator

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

I've seen users struggle with knowing that they sometimes have to do import * as pkg. I wonder if there's some sort of warning we could print in dev mode when they don't do this in order to guide them towards the correct solution?

@bluwy
Copy link
Member Author

bluwy commented Oct 4, 2023

I've seen users struggle with knowing that they sometimes have to do import * as pkg. I wonder if there's some sort of warning we could print in dev mode when they don't do this in order to guide them towards the correct solution?

There's actually an instance of this in Vite you can test out.

import * as optimizedWithNestedExternal from '@vitejs/test-optimized-with-nested-external'
import * as optimizedCjsWithNestedExternal from '@vitejs/test-optimized-cjs-with-nested-external'

Without the * as it reports (Vite emulated error):

SyntaxError: The requested module '@vitejs/test-optimized-with-nested-external' does not provide an export named 'default'
    at Object.get (file:///Users/bjorn/Work/oss/vite/packages/vite/dist/node/chunks/dep-da74c78d.js:56763:23)
    at render (/Users/bjorn/Work/oss/vite/playground/ssr-deps/src/app.js:74:46)
    at async file:///Users/bjorn/Work/oss/vite/playground/ssr-deps/server.js:98:23

We can definitely add more hints/suggestions here, but I think we can improve on that in a later PR.

@benmccann
Copy link
Collaborator

Yeah, I wasn't sure if users know how to fix it though. The error message could be tweaked a bit to include a solution like The requested module '@vitejs/test-optimized-with-nested-external' does not provide an export named 'default'. Try importing with: import * as pkg from '@vitejs/test-optimized-with-nested-external'

@bluwy
Copy link
Member Author

bluwy commented Oct 6, 2023

I think we should wait to see how users are often hitting this before adding the hints. I'm afraid to add some suggestions that could be misleading otherwise. Plus there's a lot of resource for that error message on the web that they should be able to find different solutions to what they're hitting.

sapphi-red
sapphi-red previously approved these changes Oct 6, 2023
Copy link
Member

@sapphi-red sapphi-red 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 the github discussion link is updated later)

@sapphi-red
Copy link
Member

It would be nice to add this to docs/guide/migration.md.

@bluwy
Copy link
Member Author

bluwy commented Oct 10, 2023

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Oct 10, 2023

📝 Ran ecosystem CI: Open

suite result
analogjs ✅ success
astro ✅ success
histoire ✅ success
ladle ✅ success
laravel ✅ success
marko ❌ failure
nuxt ✅ success
nx ✅ success
previewjs ✅ success
qwik ❌ failure
rakkas ❌ failure
sveltekit ✅ success
unocss ❌ failure
vike ✅ success
vite-plugin-pwa ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ✅ success
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success

@bluwy bluwy added this to the 5.0 milestone Oct 16, 2023
yyx990803
yyx990803 previously approved these changes Oct 19, 2023
sapphi-red
sapphi-red previously approved these changes Oct 19, 2023
@bluwy bluwy merged commit 5786837 into main Oct 19, 2023
9 of 10 checks passed
@bluwy bluwy deleted the remove-proxy-esm-ssr branch October 19, 2023 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change feat: ssr p3-significant High priority enhancement (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants