oven-sh / bun

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

Cannot find module "@panva/hkdf" #9794

Open 0-don opened 8 months ago

0-don commented 8 months ago

What version of Bun is running?

1.1.0+5903a6141

What platform is your computer?

Linux 6.8.2-arch2-1 x86_64

What steps can reproduce the bug?

I am using solid-start nextauth and running the bun app in docker container which produces this error

at processTicksAndRejections (:12:39)
[nitro] [request error] [unhandled] Cannot find module "@panva/hkdf" from "/app/.output/server/node_modules/@auth/core/jwt.js"
  at new H3Error (./.output/server/index.mjs:2086:4)  
  at createError$1 (./.output/server/index.mjs:4043:26)  
  at <anonymous> (./.output/server/index.mjs:4975:34)  
  at processTicksAndRejections (:12:39)

What is the expected behavior?

it works in the previous bun version 1.0.36

What do you see instead?

it works in the previous bun version 1.0.36

Additional information

No response

shtse8 commented 7 months ago

I have the same issue. It works on 1.0.36.

2024-04-14 14:06:25 error: Cannot find module "@panva/hkdf" from "/usr/src/app/.output/server/node_modules/@auth/core/jwt.js"
2024-04-14 14:06:25 error: script "prod" exited with code 1
2024-04-14 14:06:27 $ bun x prisma migrate deploy && bun .output/server/index.mjs
2024-04-14 14:06:27 error: Cannot find module "@panva/hkdf" from "/usr/src/app/.output/server/node_modules/@auth/core/jwt.js"
2024-04-14 14:06:27 error: script "prod" exited with code 1
2024-04-14 14:06:28 $ bun x prisma migrate deploy && bun .output/server/index.mjs
2024-04-14 14:06:29 error: Cannot find module "@panva/hkdf" from "/usr/src/app/.output/server/node_modules/@auth/core/jwt.js"
2024-04-14 14:06:29 error: script "prod" exited with code 1
2024-04-14 14:06:30 $ bun x prisma migrate deploy && bun .output/server/index.mjs
2024-04-14 14:06:31 error: Cannot find module "@panva/hkdf" from "/usr/src/app/.output/server/node_modules/@auth/core/jwt.js"
2024-04-14 14:06:31 error: script "prod" exited with code 1
2024-04-14 14:06:32 $ bun x prisma migrate deploy && bun .output/server/index.mjs
2024-04-14 14:06:32 error: Cannot find module "@panva/hkdf" from "/usr/src/app/.output/server/node_modules/@auth/core/jwt.js"
2024-04-14 14:06:32 error: script "prod" exited with code 1
2024-04-14 14:06:34 $ bun x prisma migrate deploy && bun .output/server/index.mjs
2024-04-14 14:06:35 error: Cannot find module "@panva/hkdf" from "/usr/src/app/.output/server/node_modules/@auth/core/jwt.js"
2024-04-14 14:06:35 error: script "prod" exited with code 1
shtse8 commented 7 months ago

any updates on this issue? I am still staying on 1.0.36 and failed to upgrade to the latest.

0-don commented 7 months ago

yeah waiting aswell

shtse8 commented 7 months ago

the issue continues on v1.1.7

shtse8 commented 6 months ago

the issue still continue on v1.1.12. any updates on this?

0-don commented 6 months ago

yes me to

shtse8 commented 5 months ago

I found out the reason for the issue. It seems that the latest Bun version is causing the build engine to miss tracking the dependency for the @panva/hkdf module, leaving only the web version of the code on the server side when using Bun versions later than 1.0.36.

To fix this, we need to move @panva/hkdf/dist/node/esm/ to the final build folder.

Here's the relevant section from the package.json of @panva/hkdf:

"exports": {
  ".": {
    "types": "./dist/types/index.d.ts",
    "browser": "./dist/web/index.js",
    "worker": "./dist/web/index.js",
    "import": "./dist/node/esm/index.js",
    "require": "./dist/node/cjs/index.js"
  },
  "./package.json": "./package.json"
}

If you are using Nuxt, you can add the following to your nuxt.config.ts:

build: {
  transpile: [
    '@auth/core',
    '@panva/hkdf'
  ]
}

This should ensure that the correct node version is included in the build, resolving the issue.

ghyath5 commented 5 months ago

I have similar issue with different package name. building and running it using nodejs is working

this error only appears with bun and I think this because of @authjs/core library, i'm not sure

bun i && bun --bun run build && bun --bun .output/server/index.mjs

Listening on http://[::]:3000
[nuxt] [request error] [unhandled] [500] Cannot find package "jose" from ".output/server/chunks/routes/api/auth/_..._.mjs"
  at new H3Error (./.output/server/chunks/runtime.mjs:1922:4)  
  at createError$1 (./.output/server/chunks/runtime.mjs:1955:26)  
  at <anonymous> (./.output/server/chunks/runtime.mjs:3420:25)  
  at processTicksAndRejections (:12:39)
export default defineNuxtConfig({
  build: {
    transpile: ["@auth/core", "@panva/hkdf"],
  },
  authJs: {
    // authenticatedRedirectTo: "/projects",
    // guestRedirectTo: "/",
    baseUrl: process.env.AUTH_ORIGIN,
  },
  alias: {
    cookie: "cookie",
  },...
0-don commented 5 months ago

I am using solid start doesnt seem to work there

shtse8 commented 5 months ago

confirm the issue still exists in the latest bun version.