-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
svelte-kit package
cannot include goto
function from $app/navigation
#3010
Comments
Yes you're right. SvelteKit utility functions can't be used for packaging as your library can be used for non-SvelteKit projects too. The utilities also requires to be directly imported (instead of from a package) so it is expected behaviour that it doesn't work. Perhaps we can document this though. |
If we're using a lot of svelte specific features in the library like I guess a workaround for the use case I described is to pass in the utility function as a prop to the component, though it will lock people into using svelte kit. |
For |
I totally see where you're coming from and I see the benefits of doing it that way. Especially for folks who want to make packages for non-svelte projects. However, I also see the benefits of making libraries and components specifically for svelte kit projects that let developers get all the nice sveltey things if they are invested in the ecosystem like element and component directives out of the box. I feel like that's already 80% possible without being about to access the utility functions. But I'm biased and heavily invested in the ecosystem and could very well be the odd man out here. |
Honestly I feel the same, ideally this is possible somehow, but I don't know how we could achieve this right now. |
Maybe on a |
Closing as duplicate of #1485 |
Describe the bug
When creating a component library with Svelte Kit and packaging it using
svelte-kit package
, you cannot include other functions, specificlly tested withgoto
.One of my components that will be exported was using the
goto
function from kit. It was a select element that modified a url query parameter, and then used thegoto
function to rerun theload
function. Everything works just fine in dev. I import theSelect
component I created into my project.However, when the app is build and I run
svelte-kit preview
, thegoto
function no longer works. Both the one in my exported package and the one that I import on the page as well.The error I get is:
TypeError: Cannot read properties of undefined (reading 'goto')
. Again this only happens after everything is built.Reproduction
I created a button UI component using
goto
for a simple exampleI exported it correctly and published the package on npm, the library is called
svelte-kit-goto-test
Next I installed the library as a dependency in my project, imported the
Button
. The home link used theButton
component and the about link uses the imported goto component:When previewing with
svelte-kit dev
, the navigation works as expected. When building the project and usingsvelte-kit preview
, the links don't work and we get the errorTypeError: Cannot read properties of undefined (reading 'goto') at Lt (vendor-ae893024.js:1) at HTMLButtonElement.<anonymous> (__layout.svelte-6aa37c4a.js:1)
I deployed a version with the issue: https://svelte-kit-goto-test.vercel.app/
Here the github repo: https://github.com/vpanyushenko/svelte-kit-goto-test
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
Currently removed the goto links from the library and using
window.location
which isn't ideal but works.I'm guessing this has to to with the package only including files from
$lib
but I don't quite understand how this works. If this is a feature, not a bug, does this mean that the libraries cannot use any of the svelte kit utility functions?The text was updated successfully, but these errors were encountered: