perspective icon indicating copy to clipboard operation
perspective copied to clipboard

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

Open rajsite opened this issue 1 year ago • 1 comments

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

  • Win 10

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):

  • @finos/perspective version: 3.1.0
  • Browser and version Chrome 129
  • OS Win 10
  • (if websocket) Language/version/OS of perspective server N/A

For Node.js: N/A

  • node version
  • OS

For Python N/A

  • python interpreter version (Only CPython).
  • package manager and version (conda/pip/*)
    • Are you compiling from an sdist of wheel?
  • Platform and version (Jupyter/tornado/lib/*)
  • OS

Additional Context:

N/A Add any other context about the problem here.

rajsite avatar Oct 17 '24 16:10 rajsite

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

rajsite avatar Oct 17 '24 22:10 rajsite

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.

MPizzotti avatar Oct 24 '24 08:10 MPizzotti

Do you know where we can see documentation for 2.10.1?

leestorm4520 avatar Oct 24 '24 13:10 leestorm4520

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.

MPizzotti avatar Oct 25 '24 16:10 MPizzotti

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/

aszenz avatar Oct 25 '24 17:10 aszenz

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?

rajsite avatar Oct 25 '24 17:10 rajsite

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 ?

MPizzotti avatar Nov 05 '24 14:11 MPizzotti

Do you know where we can see documentation for 2.10.1?

It's here: https://docs.rs/crate/perspective/2.10.1

I'm having the exact same problems with the latest v3 versions unfortunately.

tobilg avatar Dec 02 '24 23:12 tobilg

Duplicate #2725

We've released Perspective 3.3.0 with official Vite support (docs) and sample project. This new unbundled build does not require a plugin, but does require special bundler setup (see docs).

texodus avatar Jan 14 '25 23:01 texodus