bogeychan / elysia-polyfills Goto Github PK
View Code? Open in Web Editor NEWCollection of experimental Elysia.js polyfills
Home Page: https://npmjs.com/package/@bogeychan/elysia-polyfills
License: MIT License
Collection of experimental Elysia.js polyfills
Home Page: https://npmjs.com/package/@bogeychan/elysia-polyfills
License: MIT License
When using node 20 with Elysia
, @elysiajs/cors
and @bogeychan/elysia-polyfills/node/index.js
, we get an error with the 204 response.
Response constructor: Invalid response status code 204
I have tracked it down to the Elysia plugin, changing the Response from
return new Response('', {
status: 204
});
to the following fixes it.
return new Response(null, {
status: 204
});
I am opening the issue in this repo as it probably should be fixed in the polyfills, and not in the Bun only repo.
Elysia calls this.server.reload()
here whenever .use()
is called:
https://github.com/elysiajs/elysia/blob/9192fa90c57467a3f60fe6c5e8963e89a994a2bc/src/index.ts#L2716
This results in this runtime error:
TypeError: this.server.reload is not a function
at Elysia.compile (node_modules/elysia/dist/cjs/index.js:518:25)
I worked around this issue from the userland by monkey-patching Bun.server
to add a no-op .reload()
function to the server instance.
import '@bogeychan/elysia-polyfills/node/index.js'
const originalServe = globalThis.Bun.serve
// Implement server.reload() function. Otherwise, Elysia may crash with:
//
// TypeError: this.server.reload is not a function
// at Elysia.compile (node_modules/elysia/dist/cjs/index.js:518:25)
//
globalThis.Bun.serve = function (...args) {
const server = originalServe.apply(this, args as any)
if (!server.reload) {
server.reload = () => {}
}
return server
}
Elysia 0.5 add support for CommonJS by default, this should allow us to drop the additional step of using CLI to convert Elysia modules to CommonJS.
It would be nice if would you updated the package to support CommonJS as well.
With [email protected] when trying to return any kind of raw response (including the swagger plugin that returns a raw response for the swagger page), as long as the server timing plugin is enabled, it will return the following error:
error: TypeError: response.headers.toJSON is not a function
at mapResponse (/Users/blucky/git/work-sst/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/elysia/dist/cjs/handler.js:134:52)
at handle (eval at composeHandler (/Users/blucky/git/work-sst/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/elysia/dist/cjs/compose.js:1151:27), <anonymous>:85:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Server.handler (file:///Users/blucky/git/work-sst/node_modules/.pnpm/@[email protected][email protected]/node_modules/@bogeychan/elysia-polyfills/dist/mjs/env/node/server.js:34:35)
disabling the plugin makes it work properly
I know the server timing plugin isn't even on the chart in the README.md
, but this seems like an easy enough fix potentially, just putting a .toJSON = (self)=>JSON.stringify(self)
or something in the right place, so I figured I'd report it anyway
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.