ContextVariableMap not recognized during build from other package in monorepo
I created
src/hodo.d.ts
file in my Hono project:
Then, the type was inferred out of the box:
And, I configured the RPC feature in my React project:
It worked like a charm. but then I tried build command and encountered an error:
Does ContextVariableMap
type declaration not work with RPC feature?25 Replies
I think I found a solution.
src/hono.d.ts
:
src/index.ts
:
Did you add
export {}
to your hono.d.ts file?
Otherwise it won’t be globalI didn't and it works well?! don't know what the difference is
That did work or it didn’t?
No difference whether adding it or not. both works.
This is with the original code in there not the Variable type correct?
I don't understand your question. I'm totally new to Hono
I’m asking if you testing it with the original code you provided. Not the updated one
I did with the updated one. I'll try your suggestion with the original code
Yes
The same error happens from the React project.
I have to use screenshots on not on my computer right now. But add this is no different from using ContextVariableMap
Which means this is doing nothing
If I remove the ContextVariableMap declaration, and remain
const app = new Hono<{ Variables: Variables }>();
, typescript can't recognize it.
ofc I can do this as well:
but this way, I have to add the type to all my route filesI’m not sure what’s going on here if you take at look at my example project you’ll see how I’ve declared it and it has no issues. I don’t have to use type generics on each instance of Hono https://github.com/NicoPlyley/hono-auth/blob/main/src/app.d.ts
GitHub
hono-auth/src/app.d.ts at main · NicoPlyley/hono-auth
An example app with authentication using Hono, Drizzle, and D1. Running on CF Workers - NicoPlyley/hono-auth
I guess, the difference is that I want to use the type from another package with RPC feature. I configured a monorepo:
package.json
in the root directory:
The error happens when I try build command bun run build
from the web
project.