visgl / loaders.gl

Loaders for big data visualization. Website:

Home Page:https://loaders.gl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vite warnings caused by loaders utils accessing NodeJS functions during environment detection.

chrisgervang opened this issue · comments

A number of warnings print in dev mode when using vite, and aren't printed in production based on my testing. While seemingly harmless, these warnings are noisy. It'd be better to use an approach in loaders that either doesn't attempt to access node, or the community finds a way to suppress them in vite. So far, I haven't figured out how to do this.

For more context see vitejs/vite#11877

Warnings

  • Browser console warnings:
    Screen Shot 2023-07-17 at 1 14 57 PM
    docs link

    Vite does not automatically polyfill Node.js modules. We recommend avoiding Node.js modules for browser code to reduce the bundle size, although you can add polyfills manually.

  • vite build warnings:

Use of eval in "node_modules/@loaders.gl/worker-utils/dist/esm/lib/worker-farm/worker-body.js" is strongly discouraged as it poses security risks and may cause issues with minification.
"requireFromFile" is not exported by "__vite-browser-external", imported by "node_modules/@loaders.gl/worker-utils/dist/esm/lib/library-utils/library-utils.js".
"requireFromFile" is not exported by "__vite-browser-external", imported by "node_modules/@loaders.gl/worker-utils/dist/esm/lib/library-utils/library-utils.js".
"requireFromString" is not exported by "__vite-browser-external", imported by "node_modules/@loaders.gl/worker-utils/dist/esm/lib/library-utils/library-utils.js".
"requireFromString" is not exported by "__vite-browser-external", imported by "node_modules/@loaders.gl/worker-utils/dist/esm/lib/library-utils/library-utils.js".

Loaders Code

Examples of where loaders access node in try blocks:

Transform = stream.Transform;

createWriteStream = fs.createWriteStream;

  • A core part of the design philosophy of loaders.gl is that everything should works seamlessly both in browser and Node.
  • The main mechanism used to achieve this is the package.json browser field.
  • Bundlers are supposed to follow the file exclusion / substitution rules in the browser field when bundling.
  • However, esbuild only observes those rules in the top level package.json (so when loaders.gl is imported as libraries, the "browser" fields in the imported libraries get ignored.
  • AFAIK, vite used esbuild and so the loaders.gl node code is visible and we get these warnings.

I have kind of been hoping that esbuild would get around to fixing this but that is perhaps just wishful thinking.

Most of these if not all should be fixed in 3.4.13

Fixed in 4.0