Skip to content

Hono Netlify Adapter not working out of the box + Solution #73

@pkorac

Description

@pkorac

What's wrong? How to reproduce the bug?

When using the npm create hono@latest command to create an app for deployment to Netlify, the app doesn’t build properly.

Running netlify dev results in a series of errors:

◈ Failed to run Edge Function index:
TypeError: Import 'https://registry-staging.deno.com/@hono/hono/meta.json' failed: error sending request for url (https://registry-staging.deno.com/@hono/hono/meta.json): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
    at file:///Users/peter/Documents/explorations/hononetlify/netlify/edge-functions/index.ts:1:22
    at async file:///Users/peter/Documents/explorations/hononetlify/.netlify/edge-functions-serve/dev.js:7:35 {
  code: "ERR_MODULE_NOT_FOUND"
}
TypeError: Import 'https://registry-staging.deno.com/@hono/hono/meta.json' failed: error sending request for url (https://registry-staging.deno.com/@hono/hono/meta.json): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
    at file:///Users/peter/Documents/explorations/hononetlify/netlify/edge-functions/index.ts:1:22
    at async file:///Users/peter/.nvm/versions/node/v22.4.1/lib/node_modules/netlify-cli/node_modules/@netlify/edge-bundler/deno/config.ts:12:10 {
  code: "ERR_MODULE_NOT_FOUND"
}

What version of Hono are you using?

4.3.11

What runtime/platform is your app running on? (with version if possible)

Netlify

Solution (what worked for me)

Use the URL method of importing packages instead of jsr.

Replace the

import { Hono } from 'jsr:@hono/hono'
import { handle } from 'jsr:@hono/hono/netlify'

with

import { Hono } from "https://deno.land/x/hono@v4.3.11/mod.ts";
import { handle } from "https://deno.land/x/hono@v4.3.11/adapter/netlify/index.ts";

Or with

import { Hono } from "https://esm.sh/jsr/@hono/hono@4";
import { handle } from "https://esm.sh/jsr/@hono/hono/netlify";

Hope this helps

What is the expected behavior?

◈ Static server listening to 3999

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

◈ Loaded edge function index

What do you see instead?

◈ Failed to run Edge Function index:
TypeError: Import 'https://registry-staging.deno.com/@hono/hono/meta.json' failed: error sending request for url (https://registry-staging.deno.com/@hono/hono/meta.json): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
    at file:///Users/peter/Documents/explorations/hononetlify/netlify/edge-functions/index.ts:1:22
    at async file:///Users/peter/Documents/explorations/hononetlify/.netlify/edge-functions-serve/dev.js:7:35 {
  code: "ERR_MODULE_NOT_FOUND"
}
TypeError: Import 'https://registry-staging.deno.com/@hono/hono/meta.json' failed: error sending request for url (https://registry-staging.deno.com/@hono/hono/meta.json): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
    at file:///Users/peter/Documents/explorations/hononetlify/netlify/edge-functions/index.ts:1:22
    at async file:///Users/peter/.nvm/versions/node/v22.4.1/lib/node_modules/netlify-cli/node_modules/@netlify/edge-bundler/deno/config.ts:12:10 {
  code: "ERR_MODULE_NOT_FOUND"
}

Additional information

I solved my issue by using one of the url importing methods https://deno.land/x/hono, there are others like esm https://esm.sh/jsr/@hono/hono@4, and perhaps the create command + example could show one of them.
Appreciate this is specific to deploying on Netlify, but that's what the create template using Netlify suggest user would be able to do.

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