fix(rsc): show import chain for server-only and client-only import error #867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
server-only
andclient-only
error message #863I looked at sveltekit sveltejs/kit#14155, but
this.resolve
tracking feels more complicated, so I went with a different approach of probing module graph. It employs a separate technique for dev and build, which isn't something I wanted, but for now this should be fine.This is how new error message looks like:
Before
After
TODO
Improved the error message for
server-only
andclient-only
imports on Vite RSC plugin.These "only" packages provide errors only during runtime on their own, but I didn't see any reason not to surface as build time error, so this has been included as a "plugin feature". Read the updated documentation to learn more! https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-rsc/README.md#server-only-and-client-only-import
It's good to know Next.js also clarifies this as a "framework feature" and not package's own behavior, which I obviously referenced it when adding the doc https://nextjs.org/docs/app/getting-started/server-and-client-components