elysia icon indicating copy to clipboard operation
elysia copied to clipboard

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

Open Mikey-ShenSu opened this issue 1 year ago • 3 comments

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 avatar Mar 26 '24 18:03 Mikey-ShenSu

This happens to me too

Danieljs-codes avatar Apr 02 '24 19:04 Danieljs-codes

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();

nmquebb avatar Apr 06 '24 04:04 nmquebb

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.

Chiji1108 avatar Apr 29 '24 08:04 Chiji1108