content icon indicating copy to clipboard operation
content copied to clipboard

Nuxt server won't launch when using Bun's runtime with @nuxt/content installed

Open wJoenn opened this issue 2 years ago • 7 comments

Environment


  • Operating System: Linux
  • Node Version: v18.16.0
  • Nuxt Version: 3.7.3
  • CLI Version: 3.9.0
  • Nitro Version: 2.6.3
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools, modules
  • Runtime Modules: @nuxt/[email protected]
  • Build Modules: -

Reproduction

https://github.com/wJoenn/bun-nuxt-content

Just create a new project with

bunx nuxi init project_name
bun i -d @nuxt/content

and add the module to nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  modules: ["@nuxt/content"]
})

Describe the bug

The server won't launch when using the bun runtime. Removing @nuxt/content from the modules fixes the issue Installing other modules such as @nuxt/image or @nuxt/i18n won't cause any issue Using Node's runtime by running bun dev works too

Additional context

No response

Logs

➜  bun-nuxt-content git:(master) bun --bun dev
$ nuxt dev
Nuxt 3.7.3 with Nitro 2.6.3                                                     
                                                                                                                 
  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose


 ERROR  Cannot start nuxt:  {}    

wJoenn avatar Sep 22 '23 23:09 wJoenn

The issue with Bun is fixed in Edge Channel and will be released in v2.8.3.

farnabaz avatar Sep 26 '23 13:09 farnabaz

Hey @farnabaz , it seems like the issue is not 100% solved yet 🤔 I tried updating the reproduction I shared and the update mostly fixes it (I've got one launch out of 5 that fails but retrying usually work) but in my main repo it definitely does not work

At server launch I have this first error looping dozens of time first

[nuxt] [request error] [unhandled] [500] first argument must be an ArrayBufferView or an ArrayBuffer (near '...stantiate(wasm, obj));...')
  at new H3Error (./node_modules/h3/dist/index.mjs:45:4)  
  at createError (./node_modules/h3/dist/index.mjs:78:26)  
  at <anonymous> (./node_modules/h3/dist/index.mjs:1842:25)  
  at processTicksAndRejections (:55:39)

Then this one appears once

203 |           code ? "[worker] exited with code: " + code : "[worker] exited"
204 |         )
205 |       );
206 |     });
207 |     worker.once("error", (err) => {
208 |       err.message = "[worker init] " + err.message;
         ^
TypeError: Attempted to assign to readonly property.
     at /home/joenn/code/wJoenn/products/louisramosdev/node_modules/nitropack/dist/shared/nitro.7666102f.mjs:208:6
     at node:events:33:50
     at node:events:2:48
     at #onError (node:worker_threads:172:20)

Then this one about 5 times

error: 162 |         });
163 |       }
164 |     }
165 |     const error = createFetchError(context);
166 |     if (Error.captureStackTrace) {
167 |       Error.captureStackTrace(error, $fetchRaw);
         ^
FetchError: [GET] "/api/_mdc/highlight?code=cd+to-do-list%0Anpm+create+vue@3%0A&lang=bash&theme=%22dark-plus%22&highlights=%5B%5D": 500 
     at /home/joenn/code/wJoenn/products/louisramosdev/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:167:6
     at onError (/home/joenn/code/wJoenn/products/louisramosdev/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:143:25)
     at /home/joenn/code/wJoenn/products/louisramosdev/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:256:19
     at processTicksAndRejections (:55:76)

Again disabling @nuxt/content completly from my repo solves the problem it seems 🤔

wJoenn avatar Sep 26 '23 20:09 wJoenn

Here's the error I get on my reproduction 1 out of 5 time more or less

➜  bun-nuxt-content git:(master) bun dev   
$ bun --bun nuxt dev
Nuxt 3.7.4 with Nitro 2.6.3                                                                                                                                                                                                                                                                            10:36:37 PM
                                                                                                                                                                                                                                                                                                       10:36:37 PM
  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

✔ Nuxt DevTools is enabled v0.8.4 (experimental)                                                                                                                                                                                                                                                      10:36:38 PM
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan receive]:
github.com/evanw/esbuild/internal/helpers.(*ThreadSafeWaitGroup).Wait(...)
        github.com/evanw/esbuild/internal/helpers/waitgroup.go:36
main.runService.func2()
        github.com/evanw/esbuild/cmd/esbuild/service.go:114 +0x59
main.runService(0x1)
        github.com/evanw/esbuild/cmd/esbuild/service.go:160 +0x4ed
main.main()
        github.com/evanw/esbuild/cmd/esbuild/main.go:240 +0xa29

goroutine 18 [chan receive]:
main.runService.func1()
        github.com/evanw/esbuild/cmd/esbuild/service.go:98 +0x4a
created by main.runService
        github.com/evanw/esbuild/cmd/esbuild/service.go:97 +0x1e5

goroutine 19 [chan receive]:
main.(*serviceType).sendRequest(0xc000121ec0, {0x915100, 0xc000750000})
        github.com/evanw/esbuild/cmd/esbuild/service.go:192 +0xfa
main.runService.func3()
        github.com/evanw/esbuild/cmd/esbuild/service.go:125 +0x39
created by main.runService
        github.com/evanw/esbuild/cmd/esbuild/service.go:122 +0x31c

goroutine 276 [chan receive]:
github.com/evanw/esbuild/internal/bundler.(*scanner).scanAllDependencies(0xc000139200)
        github.com/evanw/esbuild/internal/bundler/bundler.go:1857 +0x232
github.com/evanw/esbuild/internal/bundler.ScanBundle(_, {_, _, _, _, _, _}, {_, _}, 0xc00028a240, ...)
        github.com/evanw/esbuild/internal/bundler/bundler.go:1262 +0xb36
github.com/evanw/esbuild/pkg/api.rebuildImpl({0xc00028a240, {0xc000288180, 0x1, 0x1}, {0x0, 0x0, 0x0}, {0x0, 0x1, 0x2, ...}, ...}, ...)
        github.com/evanw/esbuild/pkg/api/api_impl.go:1501 +0x2e5
github.com/evanw/esbuild/pkg/api.(*internalContext).rebuild(_)
        github.com/evanw/esbuild/pkg/api/api_impl.go:1031 +0x2a5
github.com/evanw/esbuild/pkg/api.(*internalContext).Rebuild(0x1?)
        github.com/evanw/esbuild/pkg/api/api_impl.go:1092 +0x58
main.(*serviceType).handleIncomingPacket.func5()
        github.com/evanw/esbuild/cmd/esbuild/service.go:293 +0xd5
created by main.(*serviceType).handleIncomingPacket
        github.com/evanw/esbuild/cmd/esbuild/service.go:290 +0x118d

goroutine 251 [chan receive]:
main.(*serviceType).sendRequest(0xc000121ec0, {0x915100, 0xc000614000})
        github.com/evanw/esbuild/cmd/esbuild/service.go:192 +0xfa
main.(*serviceType).convertPlugins.func2.3({{0xc0005f9910, 0x6}, {0xc000114d80, 0x5a}, {0x98472c, 0x4}, {0xc000114d80, 0x51}, 0x2, {0x0, ...}})
        github.com/evanw/esbuild/cmd/esbuild/service.go:973 +0x768
github.com/evanw/esbuild/pkg/api.(*pluginImpl).onResolve.func1({{0xc0005f9910, 0x6}, {0xc000114d80, 0x51}, {0x0, 0x0}, {{0xc000114d80, 0x5a}, {0x98472c, 0x4}, ...}, ...})
        github.com/evanw/esbuild/pkg/api/api_impl.go:1936 +0x1f5
github.com/evanw/esbuild/internal/bundler.RunOnResolvePlugins({_, _, _}, _, {0xc00022e1c0, 0xc000d22168, 0xc000d22180, 0xc0009ae0a0, 0x5, 0xc000284540}, ...)
        github.com/evanw/esbuild/internal/bundler/bundler.go:831 +0x8d5
github.com/evanw/esbuild/internal/bundler.parseFile({{0xa6f198, 0xc0009ae0c0}, {0xc00022e1c0, 0xc000d22168, 0xc000d22180, 0xc0009ae0a0, 0x5, 0xc000284540}, 0xc000138d80, 0xc00028a240, ...})
        github.com/evanw/esbuild/internal/bundler/bundler.go:397 +0x3187
created by github.com/evanw/esbuild/internal/bundler.(*scanner).maybeParseFile
        github.com/evanw/esbuild/internal/bundler/bundler.go:1385 +0xab6

goroutine 436 [chan receive]:
main.(*serviceType).sendRequest(0xc000121ec0, {0x915100, 0xc00046e8a0})
        github.com/evanw/esbuild/cmd/esbuild/service.go:192 +0xfa
main.(*serviceType).convertPlugins.func2.3({{0xc0003da260, 0xf}, {0xc000036280, 0x72}, {0x98472c, 0x4}, {0xc000036280, 0x56}, 0x2, {0x0, ...}})
        github.com/evanw/esbuild/cmd/esbuild/service.go:973 +0x768
github.com/evanw/esbuild/pkg/api.(*pluginImpl).onResolve.func1({{0xc0003da260, 0xf}, {0xc000036280, 0x56}, {0x0, 0x0}, {{0xc000036280, 0x72}, {0x98472c, 0x4}, ...}, ...})
        github.com/evanw/esbuild/pkg/api/api_impl.go:1936 +0x1f5
github.com/evanw/esbuild/internal/bundler.RunOnResolvePlugins({_, _, _}, _, {0xc00022e1c0, 0xc000d22168, 0xc000d22180, 0xc0009ae0a0, 0x5, 0xc000284540}, ...)
        github.com/evanw/esbuild/internal/bundler/bundler.go:831 +0x8d5
github.com/evanw/esbuild/internal/bundler.parseFile({{0xa6f198, 0xc0009ae0c0}, {0xc00022e1c0, 0xc000d22168, 0xc000d22180, 0xc0009ae0a0, 0x5, 0xc000284540}, 0xc000138d80, 0xc00028a240, ...})
        github.com/evanw/esbuild/internal/bundler/bundler.go:397 +0x3187
created by github.com/evanw/esbuild/internal/bundler.(*scanner).maybeParseFile
        github.com/evanw/esbuild/internal/bundler/bundler.go:1385 +0xab6
error: "nuxt" exited with code 11 (SIGSEGV)
error: script "dev" exited with code 11 (SIGSEGV)

wJoenn avatar Sep 26 '23 20:09 wJoenn

Should I open an issue on Bun instead @farnabaz ?

wJoenn avatar Oct 25 '23 10:10 wJoenn

I was able to run content starter with bun

npx nuxi init -t content <app>

Do you mind creating a. reproduction repo and specify bun/content version which you are using? The repo in the issue seems removed

farnabaz avatar Oct 26 '23 10:10 farnabaz

Ok I'm sorry but I didn't manage to create a reproduction in a new repo. So what I'm gonna is share my problematic repo https://github.com/wJoenn/louisramosdev

  • Bun version is 1.0.7
  • Nuxt version is 3.8.0
  • Nuxt Content version is 2.8.5

It's not big but it's not minimalistic either I apologize. In order to replicate the bug you can clone the repo then

cd louisramosdev
bun i
bun --bun dev

Once done you should see that the root page is not loading and you have a bunch of errors in the server log. There are 9 routes in total, 8 of which interacts with nuxt/content and those fail to load. These are

/ /blogs /blogs/use-vue-3-with-a-rails-7-api /blogs/rails-api-authentication-with-devise-and-json-web-tokens /blogs/create-a-rails-7-rest-api /blogs/frontend-webdev-from-beginner-to-developer /blogs/send-mail-on-rails-7-with-gmail /blogs/ruby-on-rails-7-and-vite

The first 2 routes fetch content from the blogs markdown files

  const blogs = await queryContent("/blogs")
    .sort({ date: -1 })
    .only(["title", "description", "cover_url", "date", "_path", "_id"])
    .limit(3)
    .find() as Blog[]

The other 6 are actual articles rendered with

<ContentDoc />

Finally the last route, /stack, has nothing to do with nuxt/content and is the only working page.

The errors I encounter on this repo are like the followings

[nuxt] [request error] [unhandled] [500] first argument must be an ArrayBufferView or an ArrayBuffer (near '...stantiate(wasm, obj));...')
  at new H3Error (./node_modules/h3/dist/index.mjs:45:4)  
  at createError (./node_modules/h3/dist/index.mjs:78:26)  
  at <anonymous> (./node_modules/h3/dist/index.mjs:1842:25)  
  at processTicksAndRejections (:61:39)
error: 162 |         });
163 |       }
164 |     }
165 |     const error = createFetchError(context);
166 |     if (Error.captureStackTrace) {
167 |       Error.captureStackTrace(error, $fetchRaw);
          ^
FetchError: [GET] "/api/_mdc/highlight?code=cd+to-do-list%0Anpm+create+vue@3%0A&lang=bash&theme=%22dark-plus%22&highlights=%5B%5D": 500 
      at /home/joenn/code/wJoenn/products/louisramosdev/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:167:6
      at onError (/home/joenn/code/wJoenn/products/louisramosdev/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:143:25)
      at /home/joenn/code/wJoenn/products/louisramosdev/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:256:19
      at processTicksAndRejections (:61:76)

wJoenn avatar Oct 26 '23 19:10 wJoenn

I just updated @nuxt/content to version 2.9.0 which fixed the second error block mentioned in my previous commend. This means my pages now actually load instead of hanging indefinitely.

I'm still experiencing the first error block I mentioned in my previous comment though.

[nuxt] [request error] [unhandled] [500] first argument must be an ArrayBufferView or an ArrayBuffer (near '...stantiate(wasm, obj));...')
  at new H3Error (./node_modules/h3/dist/index.mjs:45:4)  
  at createError (./node_modules/h3/dist/index.mjs:78:26)  
  at <anonymous> (./node_modules/h3/dist/index.mjs:1842:25)  
  at processTicksAndRejections (:61:39)

This prevent code highlighting from working properly. This code block for example

mkdir to-do-list
cd to-do-list
rails new --api -d postgresql api

looks like this with bun --bun dev image But should look like this (which it is with bun dev) image

wJoenn avatar Oct 29 '23 21:10 wJoenn