Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

mapResponse not found in module #979

Open
mjjabarullah opened this issue Dec 25, 2024 · 3 comments
Open

mapResponse not found in module #979

mjjabarullah opened this issue Dec 25, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@mjjabarullah
Copy link

What version of Elysia is running?

1.2.6

What platform is your computer?

Microsoft Windows NT 10.0.22635.0 x64

What steps can reproduce the bug?

After upgrading elysis version 1.2.6 i got mapResponse not found in module. I have removed bun.locknb file and node_modules file and installed again. Nothing works

What is the expected behavior?

bun run dev: should start elysia server

What do you see instead?

image

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

I have tried

@mjjabarullah mjjabarullah added the bug Something isn't working label Dec 25, 2024
@mjjabarullah
Copy link
Author

mjjabarullah commented Dec 25, 2024

After a deep investigation in my code "elysia-compression" plugin causes this issue. I have replaced the package with "elysia-compress" same issue occurs

@SaltyAom
Copy link
Member

Seems like plugin doesn't have been updated to 1.2 yet. You can either:

  1. wait for the plugin to update to 1.2
  2. force the plugin to use Elysia 1.2 with override and it might work
{
    "override": {
        "elysia": "1.2.6"
    }
}

Ultimately, should be solved once the plugin has been updated to 1.2

@SaltyAom SaltyAom self-assigned this Dec 27, 2024
@kaitk
Copy link

kaitk commented Jan 14, 2025

It seems resolving this issue takes some time.

Here is a temporary workaround that was good enough for us:

export const compression = new Elysia({ name: 'compressResponses' })
  .mapResponse(({ request, response, set }) => {
    const isJson = typeof response === 'object'
    const compressionRequested = request.headers.get('Accept-Encoding')?.includes('gzip')

    const text = isJson ? JSON.stringify(response) : (response?.toString() ?? '')

    // Only compress if content is larger than 2KB and compression is requested
    if (!compressionRequested || text.length < 2048) {
      return response as Response
    }

    set.headers['Content-Encoding'] = 'gzip'

    return new Response(Bun.gzipSync(new TextEncoder().encode(text)), {
      headers: {
        'Content-Type': `${isJson ? 'application/json' : 'text/plain'}; charset=utf-8`,
      },
    })
  })
  .as('plugin')

It's based on this example but works with swagger plugin and has a sensible minimal threshold (2kb)

This has no configuration options and it only supports gzip. If you need to actually also compress blobs see this gist. but i skipped it here for brevity

Usage, very similar to elysia-compress:

const app = new Elysia()
 .use(compression)
 .get('/', () => ({ hello: 'world' }))

Since it uses blocking gzipSync, it's definitely not ideal for all usecases,but might be an option for some

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

No branches or pull requests

3 participants