google / neuroglancer

WebGL-based viewer for volumetric data
Apache License 2.0
1.07k stars 295 forks source link

Vite example fails to build #543

Closed chrisj closed 6 months ago

chrisj commented 7 months ago

Webpack example works

Using google/neuroglancer as the neuroglancer dependancy.

  VITE v5.1.4  ready in 532 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
✘ [ERROR] Could not resolve "#src/datasource/boss/bossauth.html?url"

    node_modules/neuroglancer/lib/datasource/boss/credentials_provider.js:21:24:
      21 │ import redirectUrl from "#src/datasource/boss/bossauth.html?url";
         ╵                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The module "./lib/datasource/boss/bossauth.html?url" was not found on the file system:

    node_modules/neuroglancer/package.json:44:14:
      44 │     "#src/*": "./lib/*",
         ╵               ~~~~~~~~~

  You can mark the path "#src/datasource/boss/bossauth.html?url" as external to exclude it from the
  bundle, which will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "#src/util/google_oauth2_redirect.html?url"

    node_modules/neuroglancer/lib/util/google_oauth2.js:29:24:
      29 │ import redirectUrl from "#src/util/google_oauth2_redirect.html?url";
         ╵                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The module "./lib/util/google_oauth2_redirect.html?url" was not found on the file system:

    node_modules/neuroglancer/package.json:44:14:
      44 │     "#src/*": "./lib/*",
         ╵               ~~~~~~~~~

  You can mark the path "#src/util/google_oauth2_redirect.html?url" as external to exclude it from
jbms commented 7 months ago

Thanks for reporting this.

I actually have a test that the examples build correctly (python/tests/client_test.py), but it does not catch this issue for some reason.

I think this issue is due to Vite's optimizeDeps dependency scanner, because the vite.config.ts included with the example actually disables the data sources that require those HTML files.

npm run build does work with the example, but that uses a separate build process --- and the html files don't get used in this case due to those data sources being disabled. It still works after modifying vite.config.ts to enable all data sources, though.

I think the problem is due to a bug or limitation of the optimizeDeps scanner, but I will need to investigate more to figure out exactly what the issue is, how to work around it, and why it doesn't get triggered by the existing test of building example.