elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.72k stars 206 forks source link

`t` is `undefined` when imported from `elysia/type-system` #723

Closed bogeychan closed 1 month ago

bogeychan commented 1 month ago

What version of Elysia.JS is running?

1.1.1

What platform is your computer?

WSL Ubuntu

What steps can reproduce the bug?

// index.ts
import { TypeSystem } from "elysia/type-system";

const MyReadableStream = TypeSystem.Type<ReadableStream<Uint8Array>, never>(
  "MyReadableStream",
  (_, value) => value instanceof ReadableStream
);

MyReadableStream();
bun run ./index.ts

What is the expected behavior?

no error

What do you see instead?

78  | );
179 | var isBun = typeof Bun !== "undefined";
180 | var hasHash = isBun && typeof Bun.hash === "function";
181 | var stringToStructureCoercions = [
182 |   {
183 |     from: t.Object({}),
                ^
TypeError: undefined is not an object (evaluating 't.Object')
      at ./node_modules/elysia/dist/type-system.mjs:183:11

Additional information

this used to work back in 1.0.23

reported on discord


as a workaround you can bun add @sinclair/typebox and use import { TypeSystem } from "@sinclair/typebox/system"; instead

nad-au commented 1 month ago

I have exactly the same problem but I'm not referencing TypeSystem anywhere. However I do have many TypeBox imports all using Elysia references. Should I swap out everything for TypeBox equivalents?

nad-au commented 1 month ago

I renamed my other type-system resources and I think the app is working but I need to check thoroughly.

From:

import { TypeCompiler } from 'elysia/type-system'
import type { TypeCheck } from 'elysia/type-system'

to:

import { TypeCompiler } from '@sinclair/typebox/compiler'
import type { TypeCheck } from '@sinclair/typebox/compiler'