Skip to content

Runtime error with TypeScript path aliases in Hono deployment: Cannot find package '@/constants' #14058

@ruchernchong

Description

@ruchernchong

Description

Deploying a Hono application with zero configuration to Vercel works successfully. However, when running the API, a runtime error is thrown when using TypeScript path aliases.

Error

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@/constants' imported from /var/task/src/index.js

Reproduction

Repository: https://github.com/ruchernchong/hono-vercel-path-alias-error

Configuration

tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "strict": true,
    "skipLibCheck": true,
    "types": ["node"],
    "jsx": "react-jsx",
    "jsxImportSource": "hono/jsx",
    "outDir": "./dist",
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  },
  "exclude": ["node_modules"]
}

package.json:

{
  "name": "hono",
  "type": "module",
  "dependencies": {
    "hono": "^4.9.10"
  }
}

Code Structure

  • src/index.ts - imports from @/constants
  • src/constants/index.ts - exports the constant

Package Managers Tested

This issue occurs with both:

  • Bun
  • pnpm

Expected Behavior

Path alias should work during runtime as well.

Environment

  • Node.js: v22.18.0
  • Hono: v4.9.10
  • Module system: ESM ("type": "module")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions