Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Using both Static and HTML plugins segfaults on Bun >=1.0.27 #524

Open
Chooks22 opened this issue Mar 9, 2024 · 1 comment
Open

Using both Static and HTML plugins segfaults on Bun >=1.0.27 #524

Chooks22 opened this issue Mar 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Chooks22
Copy link

Chooks22 commented Mar 9, 2024

What version of Elysia.JS is running?

1.0.0-beta.14

What platform is your computer?

Linux 6.7.9-zen1-1-zen x86_64 unknown

What steps can reproduce the bug?

import { $ } from 'bun'

await $`mkdir repro`.quiet()

$.cwd('./repro')

await $`bun init -y`.quiet()
await $`mkdir public`.quiet()
await $`bun add elysia@next @elysiajs/{static,html}@next`

const code = `
import Elysia from 'elysia'
import { html } from '@elysiajs/html'
import { staticPlugin } from '@elysiajs/static'

new Elysia()
  .use(staticPlugin({ prefix: '/static' }))
  .use(html())
  .listen(3000, async () => {
    console.log('fetching data with flags:', process.execArgv)
    const res = await fetch('http://localhost:3000/static/test.txt')
    const data = await res.text()
    console.log('got data: %s', data)
    process.exit()
  })
`.trim()

await Bun.write('repro/public/test.txt', 'foo')
await Bun.write('repro/index.ts', code)

await $`bun run --watch index.ts`
await $`bun run index.ts`

What is the expected behavior?

fetching data with flags: [ "--watch" ]
got data: foo
fetching data with flags: []
got data: foo

What do you see instead?

fetching data with flags: [ "--watch" ]
got data: foo
fetching data with flags: []

Additional information

Same issue on v0.8.x of Elysia
Adding --watch or --hot flags to bun run works around the issue

@Chooks22 Chooks22 added the bug Something isn't working label Mar 9, 2024
@hambergerpls
Copy link
Contributor

hambergerpls commented Mar 10, 2024

I'm experiencing the same problem when using @elysiajs/html with @elysiajs/static. As a temporary workaround, I created an assets endpoint with a wildcard and use Bun.file to retrieve them.

//index.jsx

import { Elysia, t } from 'elysia';
import { html } from "@elysiajs/html";

new Elysia()
    .use(html())
    .get('/assets/*', ({ set, params }) => {
        const file = Bun.file(`${import.meta.dir}/assets/${params['*']}`);
        set.headers['Content-Type'] = file.type;
        return file.text();
    })
    .get('/', () => {
        return (
            <html lang='en'>
                <head>
                    <script src="assets/js/htmx.min.js" />
                </head>
                <body>
                    <form hx-post="/" hx-swap="afterend">
                        <input type="text" name="name" />
                        <button type='submit'>Click Me!</button>
                    </form>
                </body>
            </html>
        )
    })
    .post('/', ({ body }) => {
        return (<script>alert("{body.name}!")</script>);
    }, {
        body: t.Object({ name: t.String() })
    })
    .listen(9999, ({ port }) => {
        console.log(`Server is running on port ${port}`)
    });

But I think the segmentation fault is related to Bun.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants