Giter Site home page Giter Site logo

Comments (6)

luukvhoudt avatar luukvhoudt commented on June 8, 2024 1

Copy, pasting the following test from this repo into my project resulted in the same type error.

https://github.com/honojs/middleware/blob/main/packages/zod-validator/test/index.test.ts

I see we got one thing in common, I'm also using Bun for my project. Now using Bun v1.0.23 and Hono v3.12.4

from middleware.

and-rose avatar and-rose commented on June 8, 2024

Yeah, I just tried pasting my code into the repo's test case using Node v18.17.0 and didn't get the type error. This looks like a bun specific thing for sure.

from middleware.

luukvhoudt avatar luukvhoudt commented on June 8, 2024

With the intention to create a new issue over at the Bun repository I was trying to create a minimal reproducible example. However, I didn't manage to trigger the error or I did managed to get it working without a type error.

These are the steps I followed:

  1. bunx create-hono ./reproduction --template bun
  2. cd reproduction/
  3. bun add @hono/zod-validator zod
  4. bun add --dev typescript
  5. Change the src/index.ts:
    import { Hono } from 'hono'
    import { zValidator } from '@hono/zod-validator'
    import { z } from 'zod'
    
    const app = new Hono()
    
    app.get(
      '/', 
      zValidator('query', z.object({foo: z.string()})),
      (c) => c.text('Hello Hono!'),
    )
    
    export default app
  6. Change the tsconfig.json:
    {
      "compilerOptions": {
        "target": "ES2022",
        "moduleResolution": "bundler",
        "esModuleInterop": true,
        "strict": true,
        "jsx": "react-jsx",
        "jsxImportSource": "hono/jsx"
      }
    }
  7. bun --bun tsc

Maybe our projects have problematic settings in the tsconfig.json. I will get back to this issue some time later with the feedback of how this finding might have affected my project. Maybe I can figure out what setting caused the error.

from middleware.

and-rose avatar and-rose commented on June 8, 2024

It might have something to do with adding the typescript dependency to the bun project? I couldn't 100% confirm that it's what helped but the second I ran bun add --dev typescript the error cleared from my project. Might be because the hono bun template doesn't have typescript in the package.json?

from middleware.

yusukebe avatar yusukebe commented on June 8, 2024

I can't reproduce it. No error occurs when I try @luukvhoudt's steps.

Screenshot 2024-01-18 at 12 26 44

The error may occur if the hono files referenced by hono and @hono/zod-validator are different.

from middleware.

and-rose avatar and-rose commented on June 8, 2024

I can confirm what fixed the issue on my WSL machine and MacOS was upgrading bun to v1.0.23 and rm -rf'ing my node_modules followed by a bun i

bun upgrade
rm -rf node_modules
bun i

You should be able to replicate the issue by downgrading back to v1.0.22 and reinstalling your node_modules. You can downgrade like this

curl -fsSl https://bun.sh/install | bash -s "bun-v1.0.22"

I'm happy to close this if this helps you guys too.

Edit:

Not too sure which one of the fixes specifically helped it but looks like bun had some peer dependency resolution fixes in 1.0.23.
https://bun.sh/blog/bun-v1.0.23

from middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.