Esbuild bundle uses "browser" platform which causes depenency issues.
I have a problem with esbuild. I'm trying to use the unified with remark-parse on server side. It uses nested dependency decode-named-character-reference which has multiple exports dependent on platform. ESBuild set platform to "browser", which causes push to fail because it tries to bundle index.dom.js instead of index.js.
https://github.com/get-convex/convex-js/blob/main/scripts/bundle-server.mjs
GitHub
convex-js/scripts/bundle-server.mjs at main · get-convex/convex-js
TypeScript/JavaScript client library for Convex. Contribute to get-convex/convex-js development by creating an account on GitHub.
9 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Ping pong
ah that's unfortunate. do you have ideas for options here? the browser platform is I think just the most common platform with a similar environment, as many things bundling for server-side assume node otherwise
I don't know why convex esbuild is using "browser" platform I assume there is some reason. But some bundlers allow overriding the bundling path. Basically the limitation is the lack of possibility to extend convex configuration or esbuild with some kind of clause or plugin. I did the most outrageous hack using
patch-package
with overriding the "browser" export path, but it all fell apart when using the same package in the convex backend and react frontend since it's the same pull in node_modules
.
It's a tough problem to solve since it's affecting nested modules in the dependency tree. And I have no idea why browser platform is used in convex esbuild.We picked browser as many libraries didn't work without it (they assume a node environment, whereas v8 has the web libraries, e.g. web crypto and not
fs
). We could have a custom platform, but that'd require convincing all the incompatible libraries to special-case us. What platform do you think makes more sense?We don't have many options to choose from, "node", "browser", "neutral" in esbuild AFAIK. Taking into account what you've said it seems like there is no perfect option to pick. No clue how would "neutral" fit in here.
Regarding custom platform, would it be possible to configure esbuild in a way that - If dependency has
"convex": "index.js"
then we bundle the overwritten path otherwise we use regular "browser" platform behaviour.
This would at least allow us to do the nasty hack with patch-package
+ postinstall
by injecting the "convex" and node_modules would behave properly for frontend bundling.TIL We already target multiple platforms, including "convex" and "browser". If the dependency could add
"convex": "index.js"
before the "browser" case, it'd work I believeOkay I will check
@Ian Checked and this doesn't work I added the "convex" export and it picks up browser anyway.
You can try to reproduce that with decode-named-character-reference package
Is this for the "use node"environment? I believe we only use that target when we're bundling for our default v8 environment