(Better) Node.js builtin emulation for client-side JS
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
I've found many NPM packages that almost work in SvelteKit client-side JS, but their access to node builtins like process and buffer results in errors. For example:
ReferenceError: process is not defined(json-schema-to-zod)ReferenceError: process is not defined(google-photos-album-image-url-fetch)Module "path" has been externalized for browser compatibility. Cannot access "path.extname" in client code.(gphotos-scraper)
There is a work-around for these errors, but it's neither obvious nor simple:
Most average Svelte devs may just assume it's not possible (like I did at first).
Describe the proposed solution
Ideally SvelteKit would provide something similar to Parcel's Polyfilling & Excluding Builtin Node Modules
The SvelteKit DX would be greatly enhanced by integrating the work-arounds linked above as either default or optional configurations.
If the work-arounds are not included (by default), detecting this class of error and giving meaningful error messages pointing to the correct work-arounds would still be very helpful.
Alternatives considered
- It is possible to use the work-arounds linked above.
- Limiting use of the problem modules to server-side JS, and wrapping with internal endpoints.
Importance
would make my life easier
Additional Information
Simple repro demonstrating problem:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked minimal reproduction and its node-builtins-bug branch, then review the reported process, buffer, and path failures alongside the linked Vite and Parcel guidance. Done would require an agreed SvelteKit approach for client-side Node builtin emulation, or actionable diagnostics that direct users to supported workarounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, vite
- Domain
- build-system, frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100