oven-sh / bun

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

`Attempted import error` when running `bun i` & `bun run build` in Vercel #12100

Open MarkLyck opened 1 week ago

MarkLyck commented 1 week ago

What version of Bun is running?

1.1.12+43f0913c3

What platform is your computer?

My computer where it works: Darwin 23.5.0 arm64 arm

Vercel: (where the error appears). I'm not sure

What steps can reproduce the bug?

When deploying my nextJS app to Vercel using bun to install and build. I get the following error:

Running "bun run build"
$ next build
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
  ▲ Next.js 15.0.0-rc.0
   Creating an optimized production build ...
Failed to compile.
./node_modules/@auth/core/lib/utils/web.js
Attempted import error: 'parse' is not exported from 'cookie' (imported as 'parseCookie').
Import trace for requested module:
./node_modules/@auth/core/lib/utils/web.js
./node_modules/@auth/core/index.js
./node_modules/next-auth/index.js
./src/auth.ts
./src/app/page.tsx
./node_modules/@auth/core/lib/utils/web.js
Attempted import error: 'serialize' is not exported from 'cookie' (imported as 'serialize').
Import trace for requested module:
./node_modules/@auth/core/lib/utils/web.js
./node_modules/@auth/core/index.js
./node_modules/next-auth/index.js
./src/auth.ts
./src/app/page.tsx
> Build failed because of webpack errors
error: script "build" exited with code 1
Error: Command "bun run build" exited with 1

However I can install and build this fine on my old machine. Both Vercel and my machine is using bun version 1.1.12

Switching my package manage to pnpm and installing the same project with pnpm i and pnpm run build fixes the issue and it builds without any problem on Vercel.

It seems like there's an import bug with bun 1.1.12 and possibly still 1.1.15 when running in a Vercel Linux environment.

I have checked the cookie@0.6.0 package that's installed in my node_modules, and it looks fine. The exports exist and bun seems to be wrong.

I have tried to use resolutions to force the package to 0.6.0 but that did nothing.

To reproduce, set up next-auth@5 in any nextjs project and attempt to deploy it to Vercel.

next-auth@5 uses the @auth/core package which relies on the cookie package where it imports parse and serialize like this:

import { parse as parseCookie, serialize } from "cookie"

running npm list it shows there's no other things in my project using cookie.

Seems to be a bug in bun since it works when doing nothing other than switching the install / build to pnpm

What is the expected behavior?

The project should install and build without errors like it does with pnpm or npm.

What do you see instead?

Error above.

Additional information

No response

museadam commented 1 week ago

I cannot reproduce the error... When running this repo: (https://github.com/rajput-hemant/nextjs-template) on Vercel it works with the commands bun install and bun run build. Also Vercel is defaulting my bun version to 1.1.16.