Skip to content

feat: expose 'svelte/internal' #10987

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

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-mugs-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: expose 'svelte/internal' to prevent Vite erroring on startup
3 changes: 3 additions & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"./elements": {
"types": "./elements.d.ts"
},
"./internal": {
"default": "./src/internal/index.js"
},
"./internal/client": {
"default": "./src/internal/client/index.js"
},
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/scripts/check-treeshakeability.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ console.group('checking treeshakeability');
for (const key in pkg.exports) {
// special cases
if (key === './compiler') continue;
if (key === './internal') continue;
if (key === './internal/disclose-version') continue;

for (const type of ['browser', 'default']) {
Expand Down
5 changes: 5 additions & 0 deletions packages/svelte/src/internal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// TODO we may, on a best-effort basis, reimplement some of the legacy private APIs here so that certain libraries continue to work. Those APIs will be marked as deprecated (and should noisily warn the user) and will be removed in a future version of Svelte.

throw new Error(
Copy link
Member

Choose a reason for hiding this comment

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

I vaguely remember @dominikg / @bluwy trying this approach to throw an error for better visibility what's happening, but IIRC the node/bundlers/whatever swallow the error and show something opaque instead.

In general I would prefer if we instead would keep svelte/internal and expose a browser+default condition for the client/server entry points

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue people are facing isn't that they're importing this module and it's failing, it's that Vite is attempting to preoptimize stuff based on what vite-plugin-svelte tells it. So there are two possible solutions:

  • this one
  • vite-plugin-svelte dynamic generates the list of Svelte subpackages from the package.json it finds

Ultimately we need both, but this is what will fix the errors for the largest number of people most quickly

Copy link
Member Author

Choose a reason for hiding this comment

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

In general I would prefer if we instead would keep svelte/internal and expose a browser+default condition for the client/server entry points

I really don't think that's the right approach — having different export conditions is a good way to expose a common API across different environments (such as onMount being a no-op in SSR, but still existing), but using it to have the same module specifier mean two completely different modules feels like a recipe for confusion

Copy link
Member

@dummdidumm dummdidumm Mar 29, 2024

Choose a reason for hiding this comment

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

Who would be confused by that? It's an internal implementation detail that only concerns us. And doing it this way would mean less configs in the wild that need to be adjusted, which I value way higher.

For a quick fix I agree that this is the best option for now

`Your application, or one of its dependencies, imported from 'svelte/internal', which was a private module used by Svelte 4 components that no longer exists in Svelte 5. It is not intended to be public API. If you're a library author and you used 'svelte/internal' deliberately, please raise an issue on https://github.com/sveltejs/svelte/issues detailing your use case.`
);