Skip to content

Task CLI commands fail when dev server isn't using default port 3000 #3264

Closed

Description

@LiamDochartaigh

Environment

Node: v22.14.0
Nitro: 2.11.6

Reproduction

  1. Start Nitro dev server with a custom port (not 3000)
  2. Run nitro task list or another CLI command
  3. See error message: "http://localhost:3000/_nitro/tasks": <no response> fetch failed

Describe the bug

When running the Nitro development server on a port other than the default 3000, CLI commands that communicate with the dev server (such as nitro task list) fail despite the server running properly. The errors show port 3000 is always used with the fetch.

Issue stems from below.

// nitro/src/task.ts

  const devFetch = ofetch.create({
    baseURL: `http://${buildInfo.dev.workerAddress.host || "localhost"}:${
      buildInfo.dev.workerAddress.port || "3000"
    }`,
    // @ts-expect-error
    socketPath: buildInfo.dev.workerAddress.socketPath,
  });

Below is a potential fix that does work in my case, to properly allow dev server communication.

import { Agent } from 'undici';

 const devFetch = ofetch.create({
    baseURL: `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"
      }`,
    dispatcher: new Agent({
      connect: {
        socketPath: buildInfo.dev.workerAddress.socketPath
      }
    })
  });

This fixes the issue, though it results in bundling warnings:

  • Implicitly bundling "undici"
  • Potential implicit dependencies found: node:sqlite
    ERROR Exiting with code (1). You can change this behavior by setting failOnWarn: false.

Additional context

No response

Logs

Activity

  1. added
    pending triage
    on Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions