hono
hono copied to clipboard
Absolute imports break `typeof app` for rpc client.
What version of Hono are you using?
3.10.2
What runtime/platform is your app running on?
bun
What steps can reproduce the bug?
I have a separate file that has a single test route in it
// test-route.ts
import { Hono } from 'hono';
export const route = new Hono().get('/', async (c) => c.text('Hello World!'));
in the below code notice import { route } from 'test-route';
is an absolute import which breaks the type (see screenshot)
// index.ts
import { Hono } from 'hono';
import { route } from 'test-route';
const app = new Hono().route('/test', route);
export type AppType = typeof app;
export default app;
in the below code, notice that import { route } from './test-route';
is a relative import which works (see screenshot)
import { Hono } from 'hono';
import { route } from './test-route';
const app = new Hono().route('/test', route);
export type AppType = typeof app;
export default app;
What is the expected behavior?
I get strong types with relative imports. I would expect the same behavior with absolute imports.
What do you see instead?
I have a broken type with absolute imports.
Additional information
No response
I have found that this also happens when using path aliases. Version 4.0.10
this also happen when I using mono repos, in this case, the api was move to api-package and the client side - react app import the api-package
I am not ignoring the issue because I don't see a good solution. If anyone knows of a better way, please let me know.
I think add the test-route
module from node_modules
to paths mapping can help this to work @yusukebe
This is not something that must be handled by Hono.
// Path mapping
"paths": {
"@lib/*": ["lib/*"],
"test-route": ["node_modules/test-route-lib"] // Maps all imports starting with "~/" to "./lib/"
},
Also check: https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths#typescript-transform-paths-plugin, basically the idea is to transform absolute imports to relative imports.