oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.56k stars 2.72k forks source link

Bun install is failing in vercel (Turbo Repo) #8010

Closed mmarifat closed 9 months ago

mmarifat commented 9 months ago

What version of Bun is running?

1.0.21

What platform is your computer?

vercel

What steps can reproduce the bug?

Deploy any project in vercel using bun install (bun.lockb included)

What is the expected behavior?

The installation should be finished

What do you see instead?

Error: Cannot find module '/vercel/path0/install.js'

image

Additional information

No response

lmachens commented 9 months ago

Same issue here. I have a Next.js v14.0.4 project in a turbo repo workspace.

[07:52:01.423] Running build in Washington, D.C., USA (East) – iad1
[07:52:01.537] Cloning github.com/lmachens/the-hidden-gaming-lair (Branch: main, Commit: c9b4326)
[07:52:01.912] Previous build cache not available
[07:52:03.898] Cloning completed: 2.361s
[07:52:04.628] Running "vercel build"
[07:52:05.089] Vercel CLI 33.0.2
[07:52:05.225] > Detected Turbo. Adjusting default settings...
[07:52:05.794] Running "install" command: `bun install`...
[07:52:05.855] bun install v1.0.21 (837cbd60)
[07:52:08.931] node:internal/modules/cjs/loader:1080
[07:52:08.932]   throw err;
[07:52:08.932]   ^
[07:52:08.932] 
[07:52:08.932] Error: Cannot find module '/vercel/path0/install.js'
[07:52:08.932]     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
[07:52:08.932]     at Module._load (node:internal/modules/cjs/loader:922:27)
[07:52:08.933]     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
[07:52:08.933]     at node:internal/main/run_main_module:23:47 {
[07:52:08.933]   code: 'MODULE_NOT_FOUND',
[07:52:08.933]   requireStack: []
[07:52:08.933] }
[07:52:08.933] 
[07:52:08.934] Node.js v18.18.2
[07:52:08.934] 
[07:52:08.934] error: postinstall script from "esbuild" exited with 1
[07:52:08.974] Error: Command "bun install" exited with 1
[07:52:11.429] 
mmarifat commented 9 months ago

Temporary solution is to downgrade to bun@1.0.15.

image

Vercel's official doc link

Another nightmare during weekends :(

arvinxx commented 9 months ago

+1 , LobeChat also meet this: https://github.com/lobehub/lobe-chat/issues/953

Jarred-Sumner commented 9 months ago

I’m not sure yet what the cause of this is, but I will look into fixing this now

Jarred-Sumner commented 9 months ago

I have a likely fix in #8025, but to fix it without waiting to upgrade versions

Run this command one time in your repository:

bun install --force

Commit the updated bun.lockb file

And try again

lmachens commented 9 months ago

I have a likely fix in #8025, but to fix it without waiting to upgrade versions

Run this command one time in your repository:

bun install --force

Commit the updated bun.lockb file

And try again

I called bun install --force and pushed the updated lock file. Still the same issue on Vercel. Bun version 1.0.21

mmarifat commented 9 months ago

I have a likely fix in #8025, but to fix it without waiting to upgrade versions

Run this command one time in your repository:

bun install --force

Commit the updated bun.lockb file

And try again

Thanks for the quick reply I had tried the --force thing first, no luck. Will be trying again as soon as the PR gets merged

moinulmoin commented 9 months ago

facing the same issue,

Jarred-Sumner commented 9 months ago

In about 40 minutes, @mmarifat @moinulmoin please run bun upgrade --canary and let me know if the issue continues to occur

mmarifat commented 9 months ago

In about 40 minutes, @mmarifat @moinulmoin please run bun upgrade --canary and let me know if the issue continues to occur

We will have to wait until vercel upgrade themeselves. Also may be vercel won't release canary flagged version

Jarred-Sumner commented 9 months ago

In about 40 minutes, @mmarifat @moinulmoin please run bun upgrade --canary and let me know if the issue continues to occur

We will have to wait until vercel upgrade themeselves. Also may be vercel won't release canary flagged version

You don’t need to wait. You can run bun upgrade --canary in a postinstall script and it will work.

moinulmoin commented 9 months ago

tried, but no luck! @Jarred-Sumner

image image

Jarred-Sumner commented 9 months ago

Okay, it looks like it's an issue with the current working directory not being set correctly for lifecycle scripts. This wasn't an issue previously because bun install wasn't running lifecycle scripts without explicitly being allowed via "trustedDependencies". ~This seems to be an issue somewhat specific to CI environments like Vercel & Google Cloud Run because ~/proc/self/fd/* is not accessible, which makes it harder for Bun to turn file descriptors into absolute fully-resolved file paths.~ Edit: after more investigation, this specific detail is not correct (that it is not prefixing the path is what is happening, but I don't think /proc/self is why)

Workaround 1: Disable lifecycle scripts for dependencies

Set "trustedDependencies": ["a-package-which-does-not-exist"] in package.json

{
  "name": "my-package-name",
   ...
   "trustedDependencies": ["any-string-can-go-in-here-this-will-disable-lifecycle-scripts-to-run-for-dependencies"]
}

Workaround 2: Disable all lifecycle scripts

Alternatively, you could also disable lifecycle scripts entirely:

bun install --ignore-scripts

But that would mean project/workspace lifecycle scripts also do not execute.

moinulmoin commented 9 months ago

@leerob

Okay, it looks like it's an issue with the current working directory not being set correctly for lifecycle scripts. This wasn't an issue previously because bun install wasn't running lifecycle scripts without explicitly being allowed via "trustedDependencies". This seems to be an issue somewhat specific to CI environments like Vercel & Google Cloud Run because /proc/self/fd/* is not accessible, which makes it harder for Bun to turn file descriptors into absolute fully-resolved file paths.

Workaround 1: Disable lifecycle scripts for dependencies

Set "trustedDependencies": ["a-package-which-does-not-exist"] in package.json

{
  "name": "my-package-name",
   ...
   "trustedDependencies": ["any-string-can-go-in-here-this-will-disable-lifecycle-scripts-to-run-for-dependencies"]
}

Workaround 2: Disable all lifecycle scripts

Alternatively, you could also disable lifecycle scripts entirely:

bun install --ignore-scripts

But that would mean project/workspace lifecycle scripts also do not execute.

cc: @leerob , sorry to bother you lee

zachbryant commented 9 months ago

In about 40 minutes, @mmarifat @moinulmoin please run bun upgrade --canary and let me know if the issue continues to occur

I was having a similar issue with a different package on stable, but upgrading to canary and force installing worked for me. Thanks!

krall12 commented 9 months ago

I'm still not having any luck on Vercel. Still getting the same error with everything I've tried.

I've tried

Screenshot 2024-01-08 at 9 00 14 AM
schulzf commented 9 months ago

I'm still not having any luck on Vercel. Still getting the same error with everything I've tried.

I've tried

  • Updating to canary locally and then force installing and deploying that
  • Adding a random trustedDependency to the package.json and deploying that
  • Running bun install --ignore-scripts as an install script
  • Running npx bun@canary install as an install script
Screenshot 2024-01-08 at 9 00 14 AM

have you tried npx bun@1.0.15 install ? this temporarily solved this issue for us

EndangeredMassa commented 9 months ago

As soon as a new version of bun is published, we'll update it at Vercel. Until then, it sounds like overriding the install command to npx bun@1.0.15 install works for most people. Just remember to undo that change when the new release comes out if you want to stay on latest bun.

dkmooers commented 9 months ago

Overridding the install command didn't work for me, but changing to Node 20 did as a temporary workaround

Jarred-Sumner commented 9 months ago

The bug was caused by Bun depending on posix_spawn_file_actions_addchdir_np for the current working directory to be set in spawned lifecycle scripts. This function was introduced in glibc in 2.29, and Vercel uses glibc 2.26 at the time of writing.

This didn't impact bun install until Bun v1.0.17 or so because previously when we did run lifecycle scripts, they were run in serial, blocking the main thread and they were using one of the zig standard library functions for this instead of posix_spawn. We didn't catch this in tests because our CI uses glibc >= 2.29.

The fix was to implement a posix_spawn-like polyfill for Linux.

Once #8064 finishes building (about 40 minutes), please once again try running bun upgrade --canary && bun install.

kkortes commented 9 months ago

So at this point in time we're out of luck on Vercel's end until they update glibc to 2.29?

I did the local bun upgrade --canary && bun install and shipped it, but the build kept on failing with the same error.

Overriding the install command with: npx bun@1.0.15 install works for me, as a temporary fix

asterikx commented 9 months ago

Upgrading to Node 20 worked for me as a temporary fix. I'm logging Node and Bun versions as part of my build script. Vercel's node 20 environment is currently using node@20.9.0 and bun@1.0.6 in case this helps.

pablodz commented 9 months ago
bun upgrade --canary && bun install

worked

example log vercel

[15:49:56.362] Running build in Washington, D.C., USA (East) – iad1
[15:49:56.624] Cloning github.com/pablodz/eventpulse (Branch: main, Commit: 3da6547)
[15:49:57.549] Skipping build cache, deployment was triggered without cache.
[15:49:58.018] Cloning completed: 1.394s
[15:49:58.241] Running "vercel build"
[15:49:58.729] Vercel CLI 33.0.2
[15:49:59.388] Running "install" command: `bun upgrade --canary && bun install`...
[15:49:59.760] Downloading... 
[15:50:00.533] [1117.00ms] Upgraded.
[15:50:00.533] 
[15:50:00.534] Welcome to Bun's latest canary build!
[15:50:00.534] 
[15:50:00.534] Report any bugs:
[15:50:00.534] 
[15:50:00.534]     https://github.com/oven-sh/bun/issues
[15:50:00.534] 
[15:50:00.534] Changelog:
[15:50:00.534] 
[15:50:00.534]     https://github.com/oven-sh/bun/compare/837cbd60d5ffc5d1faf2131bbd8d968217bab2ff...main
[15:50:00.546] bun install v1.0.21 (2daade39)
[15:50:01.410] 
[15:50:01.414]  + @vitejs/plugin-vue@4.6.2
[15:50:01.417]  + autoprefixer@10.4.16
[15:50:01.417]  + postcss@8.4.33
[15:50:01.417]  + tailwindcss@3.4.1
[15:50:01.418]  + vite@5.0.11
[15:50:01.418]  + @intlify/unplugin-vue-i18n@2.0.0
[15:50:01.418]  + flowbite@2.2.1
[15:50:01.418]  + vue@3.4.6
[15:50:01.418]  + vue-i18n@9.9.0
[15:50:01.418] 
[15:50:01.418]  176 packages installed [871.00ms]
[15:50:01.420] Running "bun run build"
[15:50:01.431] $ vite build
[15:50:02.432] vite v5.0.11 building for production...
[15:50:02.466] transforming...
[15:50:04.597] ✓ 35 modules transformed.
[15:50:04.718] rendering chunks...
[15:50:04.725] computing gzip size...
[15:50:04.733] dist/index.html                  0.46 kB │ gzip:  0.31 kB
[15:50:04.734] dist/assets/index-yd44v1LZ.css  33.76 kB │ gzip:  6.27 kB
[15:50:04.734] dist/assets/index-Yg5SvsyQ.js   94.68 kB │ gzip: 35.60 kB
[15:50:04.734] ✓ built in 2.30s
[15:50:04.814] Build Completed in /vercel/output [5s]
[15:50:04.840] Deploying outputs...
[15:50:05.606] 
[15:50:05.858] Deployment completed
[15:50:08.498] Uploading build cache [11.82 MB]...
[15:50:09.517] Build cache uploaded: 1.019s
gbark commented 9 months ago

bun upgrade --canary && bun install

The bug was caused by Bun depending on posix_spawn_file_actions_addchdir_np for the current working directory to be set in spawned lifecycle scripts. This function was introduced in glibc in 2.29, and Vercel uses glibc 2.26 at the time of writing.

This didn't impact bun install until Bun v1.0.17 or so because previously when we did run lifecycle scripts, they were run in serial, blocking the main thread and they were using one of the zig standard library functions for this instead of posix_spawn. We didn't catch this in tests because our CI uses glibc >= 2.29.

The fix was to implement a posix_spawn-like polyfill for Linux.

Once #8064 finishes building (about 40 minutes), please once again try running bun upgrade --canary && bun install.

bun upgrade --canary && bun install worked like a charm. Many thanks.

EndangeredMassa commented 9 months ago

We'll be upgrading Vercel's version of bun in the next day or so: https://github.com/oven-sh/bun/releases/tag/bun-v1.0.22

EndangeredMassa commented 8 months ago

At Vercel, we're rolling out the bun update now. If there are any further issues with this, you can respond here and I'll see it.

Jarred-Sumner commented 8 months ago

Awesome. You might want to do bun upgrade --canary to get this commit in there https://github.com/oven-sh/bun/commit/0bfe3760f6dd542603aab239bb31034171bb7191, which fixes an issue when installing @napi-rs/canvas