finos / perspective

A data visualization and analytics component, especially well-suited for large and/or streaming datasets.
https://perspective.finos.org/
Apache License 2.0
8.55k stars 1.19k forks source link

`@finos/perspective` 3.1.0 fails to build due to src dependency from dist #2795

Open rajsite opened 1 month ago

rajsite commented 1 month ago

Bug Report

Steps to Reproduce:

Trying to update the vite example to perspective 3.1.0 fails for two reasons:

  1. Top-level async-await usage was added. Possible to resolve by adding a vite config and updating the target (shown in stackblitz example with addition of vite.config.ts and updates to package.json script commands to include config file)
  2. The built dist output has dependencies on the src/ts resulting in build errors like the following:

    [ERROR] No matching export in "../node_modules/@finos/perspective/src/ts/perspective-server.worker.ts" for import "default"
    
        ../node_modules/@finos/perspective/dist/esm/perspective.js:1:65:
          1 │ import u from"../../dist/pkg/web/perspective-server.wasm";import w from"../../src/ts/perspective-server.worker.js";function p(){let e,t=new Promise(r=>{e=r});return[e,t]}async function d(e,t){let[r,n]=p();e.addEventListener("message",function o(s){e.removeEventListener("message",o),r(null)}),e...
            ╵                                                                  ^

See stackblitz example based on vite example to target es2022 for tla support: https://stackblitz.com/edit/perspective-vite-build-fail

Expected Result:

Library builds successfully

Actual Result:

See above

If you are reporting a UX/UI error:

N/A

If you are reporting a library error:

N/A

If you are reporting a build or install error:

done, see above.

Environment:

For JavaScript (browser):

For Node.js: N/A

For Python N/A

Additional Context:

Related issues / discussions:

rajsite commented 1 month ago

Maybe I was just misinterpreting the docs, they seem to indicate that by default the inline builds are used and a bundler is not needed: https://docs.rs/perspective-js/latest/perspective_js/#installation

By default, Perspective inlines these assets into the .js scripts, and delivers them in one file. This has no runtime performance impact, but does increase asset load time.

And then conversation continues about using bundlers, presumable for the non-default use case of more optimal builds.

Maybe the docs are outdated with 3.0 changes? It seems like the inline builds are not the default and instead using the inline builds requires referencing @finos/perspective-viewer/dist/esm/perspective-viewer.inline.js and @finos/perspective/dist/esm/perspective.inline.js.

If that is the case then maybe this issue is a documentation should have a specific example of showing the now non-default inline builds? If that is the case I can create a PR to update that documentation.

However, even with the inline build I ran into a runtime issue (so not completely sure this is the right direction): https://github.com/finos/perspective/issues/2796

MPizzotti commented 4 weeks ago

same problem here, i've tried everything without success. note: version 2.10.1 works. i'm still getting an import error but is not blocking the build process.

leestorm4520 commented 4 weeks ago

Do you know where we can see documentation for 2.10.1?

MPizzotti commented 4 weeks ago

I don't think the documentation is available for the order version (2.xx) as far as building goes, the documentation has remained the same between the 2 major versions.

aszenz commented 4 weeks ago

Do you know where we can see documentation for 2.10.1?

You can use the Wayback machine to see old docs:

https://web.archive.org/web/20240605134744/https://perspective.finos.org/

rajsite commented 4 weeks ago

I found a workaround by using the inline builds in the latest package with vite as shown here: https://github.com/finos/perspective/issues/2796#issuecomment-2438383909

Maybe this issue should be open to capture documentation updates / updating the vite example for v3.1.2 via inline builds?

MPizzotti commented 2 weeks ago

I found a workaround by using the inline builds in the latest package with vite as shown here: #2796 (comment)

Maybe this issue should be open to capture documentation updates / updating the vite example for v3.1.2 via inline builds?

Here's a code example of the workaround:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { purgeCss } from 'vite-plugin-tailwind-purgecss';

//import { PerspectiveEsbuildPlugin } from '@finos/perspective-esbuild-plugin';
//import wasm from 'vite-plugin-wasm';
//import topLevelAwait from 'vite-plugin-top-level-await';
//import typescript from '@rollup/plugin-typescript';

export default defineConfig({
    plugins: [
        sveltekit(),
        purgeCss(),
        //    //    {
        //    //    content: ['./src/**/*.svelte', './src/**/*.html', './src/**/*.ts', './src/**/*.js'],
        //    //}
        //),
    ],
    resolve: {
        alias: {
            '@finos/perspective': '@finos/perspective/dist/esm/perspective.inline.js',
            '@finos/perspective-viewer': '@finos/perspective-viewer/dist/esm/perspective-viewer.inline.js',
            '@finos/perspective-styles': '@finos/perspective-viewer/dist/css',
            //'@finos/perspective-viewer/dist/css/solarized-dark.css': '@finos/perspective-viewer/dist/css/solarized-dark.css',
            //'@finos/perspective-viewer/dist/css/themes.css': '@finos/perspective-viewer/dist/css/themes.css'
        },
    },
    optimizeDeps: {
        esbuildOptions: {
            target: 'es2022',
        },
    },
    build: {
        target: 'es2022',
    },
});

note that the code commented out was from trial and error. when importing styles, you now have to import them using the new @finos/perspective-styles.

the only catch (quite irritating) is that i'm unable to found a workaround for getting back typescrit Types. Cold you please help me guys ?