mirror of
https://github.com/appy-one/acebase-core.git
synced 2026-05-24 22:01:23 -06:00
[GH-ISSUE #13] Vendored cuid module causes issues w/Vite bundling of client code #11
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/acebase-core#11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rcoder on GitHub (May 10, 2022).
Original GitHub issue: https://github.com/appy-one/acebase-core/issues/13
Originally assigned to: @appy-one on GitHub.
I've been trying out AceBase with SvelteKit and really enjoying the combination except for the fact that I can't seem to remove an implicit dependency on the NodeJS
processmodule being included in bundled builds.This repo has a simple case that shows what's happening: https://github.com/rcoder/dbc
tl;dr: development mode works fine, but when I make a production build of the client, the cuid
fingerprintfunction gets dragged in, which in turn usesprocess.pid.The exact error in the browser console is:
I'm by no means an expert on Vite, or modern bundling in general, but it seems to me that the shimmed browser-specific code in this module isn't being pulled in correctly.
Are there examples or recommended settings for using AceBase as a client in an SSR framwork like SvelteKit? I've certainly been bitten by other modules in this way, but my usual tricks to force ESM loading, change the bundling rules, etc. haven't seemed to help.
I'm also open to the argument that this is a SvelteKit problem, not an AceBase issue. The former is explicitly in beta, but I suspect the fundamental issue is related to Vite, not Svelte, which means it seems likely to pop up in other frameworks and tools that use Vite...which is a lot of them.
P.S.: As an aside, I'm curious what
cuidbrings to the table that, say, the more generalulidmodule (which works quite nicely across bundlers + packaging models in my experience) doesn't provide. The precise timing measurements between client and server seem nice in theory, but many of the systems I work with have no reliable clock at all and I'm a bit worried that skew between client nodes could cause issues down the road.@appy-one commented on GitHub (May 11, 2022):
Thanks for reporting this. I think this might have been caused by my recent changes that moved the browser file replacements from the main package.json to the ones in the dist/cjs and dist/esm directories. Webpack and browserify both use those correctly, but I suspect Vite does not and only looks in the root package.json.
Can you try adding the following lines to acebase-core's main package.json :
Let me know if that fixes it
Regarding your question about cuid: they are extremely collision resistant and even ID's generated within the same millisecond are sorted the right way. The time bias I added to the implementation allows all clients to use the server's time instead of their own, so they will all generate cuids that have more accurate timestamps - at least according to the server.
@appy-one commented on GitHub (May 11, 2022):
By the way, while browsing your repository (cool stuff!) I noticed in your acebase.json config file your database names have a / in them. In the browser that won't be a problem, but on the server it might because it changes the path where the files are stored on disk. I haven't tested so it might work fine, but I'd still recommend against it!
@rcoder commented on GitHub (May 11, 2022):
The
package.jsonchanges worked perfectly. Thanks!Here's the exact change that worked for me:
16cedaff8aRe: DB names with path separators: I wasn't sure myself if it would work but tried on impulse. Not only the browser client but my SvelteKit endpoints and dedicated
acebase-serverdaemon just did "the right thing".If that's surprising/not something that will necessarily keep working in future revisions I can certainly change to explicitly using the
pathoption on database creation.@appy-one commented on GitHub (May 17, 2022):
The issue's fixed with this commit, published changes in v1.16.0