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

Performance degradation found. Please call Elysia.compile() before using 'fetch' #573

Open
Mikey-ShenSu opened this issue Mar 26, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Mikey-ShenSu
Copy link

What version of Elysia.JS is running?

^1.0.9

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

I have created a sample repo, and you may clone and try out.

Github Repo

You may look at the source code of elysia here

What is the expected behavior?

When Nextjs API is called, there should be no error "Performance degradation found. Please call Elysia.compile() before using 'fetch'"

What do you see instead?

Performance degradation found. Please call Elysia.compile() before using 'fetch'

Additional information

bun dev works fine without the error printing, but when bun start after bun run build, this happens.

@Mikey-ShenSu Mikey-ShenSu added the bug Something isn't working label Mar 26, 2024
@Danieljs-codes
Copy link

This happens to me too

@kidqueb
Copy link
Contributor

kidqueb commented Apr 6, 2024

You should call compile on your Elysia instance:

const apiApp = new Elysia({ prefix: "/api" })
  .get("/", () => "hi")
  .post("/", ({ body }) => body, {
    body: t.Object({
      name: t.String(),
    }),
  })
  .use(countController)
+ .compile();

@Chiji1108
Copy link

Chiji1108 commented Apr 29, 2024

Adding .compile() will result in this.

Collecting page data  ../Users/xxx/.next/server/app/api/[[...slugs]]/route.js:549
`:t+=s+"\n",t+="\n}\n"}return Function("inject",t+=`if(error.constructor.name === "ValidationError" || error.constructor.name === "TransformDecodeError") {
                              ^

EvalError: Code generation from strings disallowed for this context
    at Function (<anonymous>)
    at a6 (/Users/xxx/.next/server/app/api/[[...slugs]]/route.js:549:31)
    at a8 (/Users/xxx/.next/server/app/api/[[...slugs]]/route.js:516:11)
    at e.compile (/Users/xxx/.next/server/app/api/[[...slugs]]/route.js:585:15168)
    at 7406 (/Users/xxx/.next/server/app/api/[[...slugs]]/route.js:609:181)
    at t (/Users/xxx/.next/server/edge-runtime-webpack.js:1:127)
    at t (/Users/xxx/.next/server/app/api/[[...slugs]]/route.js:622:102287)
    at /Users/xxx/.next/server/app/api/[[...slugs]]/route.js:622:102312
    at t.O (/Users/xxx/.next/server/edge-runtime-webpack.js:1:496)
    at /Users/xxx/.next/server/app/api/[[...slugs]]/route.js:622:102329

> Build error occurred
Error: Failed to collect page data for /api/[[...slugs]]
    at /Users/xxx/node_modules/next/dist/build/utils.js:1268:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}
   Collecting page data  .error: script "build" exited with code 1

So it needs to be set to Dynamic Mode.
https://elysiajs.com/blog/elysia-06#dynamic-mode

new Elysia({
    aot: false
})

After that, I confirmed that I could deploy it successfully.

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

4 participants