Large Codebase Migration Story #3955
Replies: 5 comments 6 replies
-
Really appreciate the feedback!
We will implement this soon
This might be fixed by #3964
Sorry about this. We haven't implemented
This will likely be fixed via default allow-list for
This is most likely a CommonJS <> ESM interop issue. If that package uses an older version of
Sorry about this. We try for it to not be a lot of work but we are still not quite ready yet for production.
This is likely fixed in #3964. It might be #3931. We added support for async fs functions in v0.7.1 and there were bugs
@jhmaster2000 is working on making it very easy to use Bun APIs in Node. This will be integrated with |
Beta Was this translation helpful? Give feedback.
-
Okay good to know, thanks. I was using So then this ends my adventure into bun land for now... The reason is, in conclusion, that it is not reliable enough yet for my codebase in production, the biggest reason being that I get segfaults that cannot be debugged by myself. Critical question: In the priorities you state segfaults are a # 1 priority, but after more than a year of creating that issue they still not solved, while you seem to be working on many other things too. How long before segfaults will be gone? I'll keep an eye out for bun becoming usable from a node environment. That would be super useful for incrementally adopting bun. If it were possible to run your code from I guess bun is already super useful for many smaller projects, and especially new projects, but unfortunately it seems to be hard to adopt for large codebases like mine. |
Beta Was this translation helpful? Give feedback.
-
UPDATE: NOT Giving up yet 😁 Initially my tsconfig was vastly different compared to what I ended up with after the bun migration. More specifically, I was compiling everything to CommonJS. This fact made it hard to make my codebase compatible with both node.js and bun. I tried to have bun compile to CommonJS but I got segfaults immideatly. This way I couldnt make the tsconfigs equal. So I tried the other way...
Now I ended up with there being just a single difference, and that is that in a node monorepo I needed This is not a big deal, because bun can also run javascript! After many trials and errors, this is what I came up with. After migrating all package.jsons to the new entrypoint, I should be able to run my code with node.js as well as with bun.js! STILL WORK IN PROGRESS. Will update soon |
Beta Was this translation helpful? Give feedback.
-
I ended up removing most references to My SSR server currently only runs in Bun (using Bun.build and serve) so I will need to run that from bun. For production I'll try to rewrite something using "node:http". I hope I can move to bun fully in the coming months, once my main instability problems are solved. Now it's done! For my typescript monorepo, each
This allows me to build using Each
Note the I created a script that allows me to toggle the main entry between Maybe this helps more people to migrate big projects. For me this is the best. way currently, since some things are still unstable for me compared to Node.js |
Beta Was this translation helpful? Give feedback.
-
Little update: I have succeeded to make my codebase non-crashing using bun. For some reason, I didn't get any segfaults lately. |
Beta Was this translation helpful? Give feedback.
-
I've succeeded migrating my monorepo from node.js to bun. My codebase currently has over 300 packages and around 100.000 lines of code. I encountered many challenges along the way, so maybe it's useful for someone (and maybe the bun team can use my feedback)
Challenges during migration to bun.js
⛔️ Bun's "node:fs" cp was missing which meant I needed to create this even before migrating.
⛔️ Bun.js seems to have a problem with reading too many files at once, or maybe some other subtle differences in the fs api. Seems to fuck up js memory in some cases. Very weird behavior... Be very careful with this.
⛔️ The
server
(serverjs.io) package relies on app-module-path which usesModule._nodeModulePaths
which does not exist in bun. Therefore, we need to get rid of server.js (we'll replace it anyway with a bun server)⛔️ Many bun-commands work in vscode terminal but not in regular terminal. There is probably a tiny difference. Not crucial for now, but need to figure this out later
⛔️ Creating an executable for the server that includes all endpoints does not work yet. It now returns `Could not resolve: "@swc/wasm". I opened an issue (#3903), but it seems not to be supported soon. So I need to expose my code as typescript (not a big deal, unless I want my project to be closed source)
⛔️ Upon installing I found that workspace "resolutions" don't work. Because of this, I had duplicate react versions in my node_modules, which causes the famous "invalid hook call" error. I had to dedupe all react and react-dom versions, which took me hours for a project with many packages. Had to install
npm
fornpm ls
to find where the problem was because bun doesn't seem to have this functionality.⛔️ I found that the package https://github.com/vega/ts-json-schema-generator works differently in bun compared to node. It cannot create the named parameters for some functions that were fine before. Apparently
declarations
is undefined and it crashes in the package. As I rely heavily on this package, I made a PR hot fix, but of course, it means the underlying primitives just work differently, and you probably want to fix that first instead of making compatibility with 100s of packages. Atfs bug
There is probably a logical explanation for this, but I encountered something very strange today with bun. I had an array of strings in a const variable. After logging the result when creating it, it seems fine. After that I called a function in which I didn't provide this variable to the function. This function then, did a lot of (unrelated) file reads using "node:fs.readFile". After this was done, I checked the string array of the const variable again, and it changed to (seemingly random) lines of contents that was in those files.
I suspect that it is some sort of memory bug in bun with fs.readFile. But to be honest, this is a guess as that function did more stuff besides reading the file. It could be another function in bun as well that somehow overwrites memory of an unrelated variable.
Ideas for interchangeability
As there are some huge blockers for me now in Bun, I am forced to return to Node.js.
It was a lot of work to move from node to bun, but the other way around is a lot easier I suspect.
I have one question, maybe someone found a solution. I have a typescript project, so my package.json in 300+ packages in my monorepo looks like this now:
Before , I had
"main": "build/index.js"
and"source": "src/index.ts"
I have also changed my tsconfig a lot. It now looks like this:
I was wondering if I can configure my
tsconfig.json
andpackage.json
's in a way that I can run my stuff withnode
as well asbun
. Of course there would also be other questions... Can I run the "bun" package in node.js? Can I use bun-types in node? If so, it would yield a much smoother migration, because I can keep trying to make it compatible while still usingnode.js
in the same codebase/branch.If anyone has experience with this or has any tips/ideas, let me know....
For now, I'm going to probably create a migration script that alters my package.json and tsconfig.json files as desired if I want to switch between bun/node, and also do all other things required.
I'll update this post later with the results.
Beta Was this translation helpful? Give feedback.
All reactions