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

Resolve @svelteuidev/core to prebundled version #421

Closed
benmccann opened this issue Aug 29, 2022 · 7 comments
Closed

Resolve @svelteuidev/core to prebundled version #421

benmccann opened this issue Aug 29, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@benmccann
Copy link
Member

Describe the bug

Bug report from Discord: https://discord.com/channels/804011606160703521/1012085571985866914/1012390467331166238

@bluwy stated:

hmm yeah there seems to be an issue with Vite's resolver. It should resolve importing @svelteuidev/core to the one in .vite/deps

Reproduction

npm create vite@latest myapp -- --template svelte-ts

... run npm run dev and it's 21 reqs.

npm i -D @svelteuidev/core

... edit Counter.svelte:

<script lang="ts">
    import {Button} from '@svelteuidev/core';

    let count: number = 0
    const increment = () => {
        count += 1
    }
</script>

<Button on:click={increment}>
    count is {count}
</Button>

... add prebundleSvelteLibraries: true, run npm run dev and it's now 369 reqs and a 4s load time.
@smui or @svelteuidev libraries do show up in node_modules/vite/.deps - but no change in actual behaviour of the requests or bundling that I can see. There is also a message that appears with SMUI stating that it cannot find source for a bunch of @Material deps from SMUI, so that is why I was testing with @svelteuidev as well as it does not have those material deps, but - same issue there

Logs

No response

System Info

tbd

Severity

annoyance

@benmccann benmccann added bug Something isn't working triage Awaiting triage by a project member labels Aug 29, 2022
@benmccann
Copy link
Member Author

If I turn on the vite-plugin-svelte debug logging I see it rsolves @svelteuidev/core/index.js via package.json svelte field of @svelteuidev/core. I.e. it seems to be returning the one in node_modules via this line:

const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);

I'm not sure what the desired code path is supposed to be though or where it might be going wrong. If I simply remove that line it seems to resolve to the correct location

@dominikg
Copy link
Member

dominikg commented Aug 29, 2022

Note that using a deep import import Button from '@svelteuidev/core/components/Button/Button.svelte'; together with preBundleSvelteLibraries it does create a small bundle and only sends 27 requests on initial devserver load.

Edit:using deep imports for multiple components of svelteuidev creates a separate bundle in .vite for every component.

@k-dahl
Copy link

k-dahl commented Aug 30, 2022

@benmccann @dominikg Worth noting that the actual library we were running into with this was SMUI, and it also has a warning message about not being able to resolve sourcemaps for any of the underlying @material deps. I had been trying @svelteuidev in an effort to narrow things down and see if the issue was specific to the missing sourcemaps, but it was not.

@k-dahl
Copy link

k-dahl commented Sep 27, 2022

This issue also impacts Flowbite Svelte. The example on their getting started page results in 236 requests being made.

Enabling the prebundleSvelteLibraries there results in breakage when rendering:

Uncaught SyntaxError: ambiguous indirect export: default [AccordionItem.svelte:35:7](http://127.0.0.1:5173/node_modules/.pnpm/flowbite-svelte@0.27.4/node_modules/flowbite-svelte/accordions/AccordionItem.svelte?v=90fca3b2)

And the specific line that it references:

import classNames from '/node_modules/.pnpm/classnames@2.3.2/node_modules/classnames/index.js?v=363d9cb2';

If I remove the experimental pre-bundle config the app renders fine.

Using a deep import drops the number of requests down to a more reasonable 25.

@dominikg dominikg removed the triage Awaiting triage by a project member label Oct 2, 2022
@benmccann
Copy link
Member Author

If we made the "svelte" field a boolean it would fix this issue as well as sveltejs/kit#2242

Rich mentioned this idea along with some of the history behind the field on Discord and I preserved it in a GitHub comment here: sveltejs/kit#1959 (comment)

@benmccann
Copy link
Member Author

@blitzd your issue appears to be a different one. I've created a new issue to track that: #463

@dominikg
Copy link
Member

fixed in vite-plugin-svelte 1.2.0 with prebundleSvelteLibraries: true the dev page now has 27 requests and is correctly loading the prebundled version of svelteuidev/core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants