nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.08k stars 624 forks source link

Nuxt .output server package cannot run with bun when @nuxt/image is present. #2437

Closed jfelsinger closed 8 months ago

jfelsinger commented 10 months ago

Environment


Reproduction

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

You can run the above in gitpod, with the link, to reproduce; or you can pull it down, build and bun .output/server/index.mjs; or you can pull it down, build and try to run the docker bun run docker. All those have been giving me the same result.

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

(Steps 1-4 can be done the regular way with npm / npx, the crux of the issue is step 5, where it actually fails).

Describe the bug

A Nuxt project's build output that has the @nuxt/image module installed doesn't seem to run with bun, errors out seemingly unable to find a package "ofetch".

I have tried running in WSL, in Docker, and in Gitpod. The built package seems to run fine by default, but once the image module is added to the project then this error is introduced and the server fails to run.

Running with node .output/server/index.mjs does not product the error.

Additional context

I am not sure if this error is better put here, or if it's better to take up this issue with the bun team. Sorry if this is the wrong place 😓

Logs

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

Try running cd .output/server/ && bun i before running bun .output/server/index.mjs.

That solved this exact issue for me.

jfelsinger commented 10 months ago

That solution does get the server to run, but it massively increases the size of the .output bundle. In my case it goes from ~8M to ~50M. The build bundle should be limited to only the packages necessary to run. Since the bundle runs with node just fine, if my thinking is right, that should be enough for it to run with bun. I am thinking of creating an issue over there for this.

Edit: I just realized that this is in nuxt/content and not the main/relevant nuxt/nuxt or nuxt/image repos. Oops. Sorry.