Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
chrisgervang opened this issue Jul 17, 2023 · 3 comments

Comments

@chrisgervang
Copy link
Collaborator

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;

@chrisgervang chrisgervang added bug Something isn't working P2 - workaround exists and removed bug Something isn't working labels Jul 17, 2023
@ibgreen
Copy link
Collaborator

ibgreen commented Aug 4, 2023

  • 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.

@ibgreen
Copy link
Collaborator

ibgreen commented Aug 29, 2023

Most of these if not all should be fixed in 3.4.13

@ibgreen
Copy link
Collaborator

ibgreen commented Oct 23, 2023

Fixed in 4.0

@ibgreen ibgreen closed this as completed Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants