BernhardWebstudio / svelte-virtual-table

An implementation of a virtual, sortable table for Svelte
20 stars 0 forks source link

Unable to use in REPLs #1

Closed jrmoynihan closed 1 year ago

jrmoynihan commented 1 year ago

I'd love to try this package out because it looks like just what I need! However, when I spun up a REPL, I ran into these issues. Might need some small bundling/export changes to be made?

In Svelte REPL (just import the package into a 'Hello World'):

<script>
    import VirtualTable from 'svelte-virtual-table'
    let name = 'world';
</script>

<h1>Hello {name}!</h1>

results in...

CleanShot 2023-10-29 at 06 36 22@2x

I'm guessing it might have something to do with the compiler options https://github.com/mattiash/generator-sort/blob/master/tsconfig.json And what the package exports in the compiled JS after build: https://github.com/mattiash/generator-sort/blob/master/package.json The build/index.js exports probably don't quite match up with the TS file with regard to its named exports.

Might be worth raising an upstream issue on generator-sort's repo too, but in the meantime, you could just copy the few functions in directly to svelte-virtual-table and add credit/citation to the source.

In SvelteLab, we at least successfully import it (probably because it has Vite doing module resolution), but are still unable to use it:

<script>
    import VirtualTable from 'svelte-virtual-table'

    let items = [1, 2, 3]
</script>

   <VirtualTable
        {items}
    >
        <tr slot="thead">
            <th data-sort="title">Title</th>
        </tr>
        <tr slot="tbody" let:item>
            <td>
                {item}
            </td>
        </tr>
    </VirtualTable>

Gives us this error:

Error: \ is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules. Otherwise you may need to fix \.

Probably related to the aforementioned issues with generator-sort, since it's the only dependency in your package, but I'm not sure.

GenieTim commented 1 year ago

Thank you very much for your report.

I could not figure out what was going wrong with generator-sort, no less because things work in the bundled example app, so I simply removed this dependency in v1.1.3, implemented sorting directly myself, and that seems to work in REPL: https://svelte.dev/repl/f9968a19ad174c048c13e4c767ae8b8a?version=4.2.2