bogeychan / elysia-polyfills

Collection of experimental Elysia.js polyfills
https://npmjs.com/package/@bogeychan/elysia-polyfills
MIT License
48 stars 2 forks source link

TypeError: Attempted to assign to readonly property. #8

Open entrptaher opened 2 months ago

entrptaher commented 2 months ago

Currently running same code in nodejs works while it throws error in bun. If we check for the runtime, the problem goes away.

Example working code:

if(!process.versions.bun){
  // allows to run same elysia on bun and nodejs
  // otherwise bun throws readonly error
  // 78 | globalThis.Bun = ElysiaBun;
  // TypeError: Attempted to assign to readonly property.
  await import('@bogeychan/elysia-polyfills/node/index.js');
}

import { Elysia } from 'elysia';
const app = new Elysia().get('/', () => ({ hello: 'Node.js👋' })).listen(8080);
console.log(`Listening on http://localhost:${app.server!.port}`);

It would be awesome if the check was done inside the codebase directly so the polyfill does not trigger in the bun runtime.