oven-sh / bun

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

Cannot find package "ofetch" when running Nuxt build output with @nuxt/image module #7142

Open jfelsinger opened 7 months ago

jfelsinger commented 7 months ago

What version of Bun is running?

1.0.11+f7f6233ea

What platform is your computer?

Linux 5.10.16.3-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

https://github.com/jfelsinger/nuxt-image-bun-reproduction

Steps to reproduce manually:

  1. Initialize a nuxt project: bunx nuxi@latest init <project-name>
  2. Install deps: bun i
  3. Install the [@nuxt/images]() module: bunx nuxi@latest module add image
  4. Build: bunx nuxi@latest build or bun run build
  5. Try to run deployment package: bun .output/server/index.mjs

Step 5, actually running the deployment package is where the failure happens. Instead of the server starting-up, like occurs when running with node .output/server/index.mjs instead there is a failure with:

error: Cannot find package "ofetch" from "/workspace/nuxt-image-bun-reproduction/.output/server/node_modules/ipx/dist/index.mjs"

What is the expected behavior?

That the the server starts when running bun .output/server/index.mjs to start the build package.

Listening on http://[::]:3000

What do you see instead?

error: Cannot find package "ofetch" from "/workspace/nuxt-image-bun-reproduction/.output/server/node_modules/ipx/dist/index.mjs"

Additional information

This issue I have reproduced in Docker, on a containerized linux environment (gitpod), and locally in WSL. The linked repo has everything setup to reproduce, and a dockerfile that can also reproduce the issue after the .output bundle is initially built.

  1. Install deps: bun i
  2. Build: bunx nuxi@latest build or bun run build

Then: bun run docker or bun .output/server/index.mjs

Running with node .output/server/index.mjs produces no such error, so perhaps it is an issue with bun's package resolution?

https://github.com/nuxt/content/issues/2437

houssemFat commented 5 months ago

I confirm the issue, below my package.json :

{
  "name": "nuxt-app",
  "private": true,
  "scripts": {
    "nuxt:build": "nuxt build",
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "knex:migrate:latest": "knex migrate:latest",
    "knex:seed:up": "knex seed:run"
  },
  "devDependencies": {
    "@nuxt/image": "^1.1.0",
    "nuxt": "^3.9.0",
    "vue": "^3.4.3",
    "vue-router": "^4.2.5"
  },
  "dependencies": {
    "@nuxt/content": "^2.10.0",
    "@nuxtjs/i18n": "next",
    "@nuxtjs/tailwindcss": "^6.10.3",
    "@vueuse/nuxt": "^10.7.1",
    "knex": "^3.1.0",
    "pg": "^8.11.3"
  }
}
NeoN0x commented 5 months ago

Same issue with the latest bun 1.0.23

vsfedorenko commented 4 months ago

same

ZTL-UwU commented 4 months ago

@jfelsinger try setting the runtime preset to bun in the nitro config. see https://nitro.unjs.io/deploy/runtimes/bun

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
    devtools: { enabled: true },
    modules: ["@nuxt/image"],
+   nitro: {
+       preset: 'bun',
+   }
})