node-server icon indicating copy to clipboard operation
node-server copied to clipboard

Vercel node issue: Cannot find module

Open winddpan opened this issue 1 year ago • 1 comments

// api/app_const.ts

export const AppConst = {
  key: "123",
}
// api/index.ts

import { Hono } from "hono"
import { handle } from "@hono/node-server/vercel"
import { AppConst } from "./app_const"

const app = new Hono().basePath("/api")

app.get("/", (c) => {
  return c.json({ message: AppConst.key })
})

export default handle(app)

already added "type": "module" in package.json

When I vist http://localhost:3000/api

Error: Cannot find module '/Users/wp/development/hono-test/src/app_const' imported from /Users/wp/development/hono-test/api/index.ts

When I modify import { handle } from "import { AppConst } from "./app_const" to import { AppConst } from "./app_const.js" the error is gone.

I wonder how can I import module without .js suffix.

By the way: when I use edge runtime, did not have this issue.

winddpan avatar Feb 01 '24 05:02 winddpan

Maybe duplicated to https://github.com/honojs/node-server/issues/84

yusukebe avatar Feb 01 '24 21:02 yusukebe