Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to run that integrated with webpack-dev-server #209

Closed
Hajime-san opened this issue Oct 30, 2024 · 2 comments
Closed

failed to run that integrated with webpack-dev-server #209

Hajime-san opened this issue Oct 30, 2024 · 2 comments

Comments

@Hajime-san
Copy link

The webpack-dev-server example failed to run that integrated with latest @hono/node-server.

% npx webpack-cli serve
[webpack-cli] Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing.
    at Server.listen (node:net:2008:11)
    at READ_WRITE (/path/to/repo/cjs/node_modules/webpack-dev-server/lib/Server.js:3332:23)
    at new Promise (<anonymous>)
    at Server.start (/path/to/repo/cjs/node_modules/webpack-dev-server/lib/Server.js:3330:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.<anonymous> (/path/to/repo/cjs/node_modules/@webpack-cli/serve/lib/index.js:158:21)
    at async Command.parseAsync (/path/to/repo/cjs/node_modules/webpack-cli/node_modules/commander/lib/command.js:935:5)
    at async Command.<anonymous> (/path/to/repo/cjs/node_modules/webpack-cli/lib/webpack-cli.js:1356:13)
    at async Command.parseAsync (/path/to/repo/cjs/node_modules/webpack-cli/node_modules/commander/lib/command.js:935:5)
    at async WebpackCLI.run (/path/to/repo/cjs/node_modules/webpack-cli/lib/webpack-cli.js:1360:9) {
  code: 'ERR_SERVER_ALREADY_LISTEN'
}

I'm not sure which library should be responsible for listening to the server, but at least in certain versions there is no problem on the webpack-dev-server side, so I reported it here.

Enivironment

% node --version          
v22.4.0

Steps to reproduce

Files

  • package.json
{
  "type": "module",
  "devDependencies": {
    "@hono/node-server": "^1.13.3",
    "hono": "^4.6.8",
    "webpack": "^5.95.0",
    "webpack-cli": "^5.1.4",
    "webpack-dev-middleware": "^7.4.2",
    "webpack-dev-server": "^5.1.0"
  }
}
  • webpack.config.js
import wdm from "webpack-dev-middleware";
import { Hono } from "hono";
import { serve } from "@hono/node-server";

const app = new Hono();
app.get("/", (c) => {
  return c.text("Hello, Hono!");
})

export default {
  entry: "./app.js",
  devServer: {
    setupMiddlewares: (_, devServer) => [
      {
        name: "webpack-dev-middleware",
        middleware: wdm.honoWrapper(devServer.compiler),
      },
    ],
    app: () => app,
    server: (_, app) =>
      serve({
        fetch: app.fetch,
      }),
  },
};
  • app.js
export function add(a, b) {
  return a + b;
}

Command

% npm ci
% npx webpack-cli serve

My guess

It seems to break after the below PR landed.

@alexander-akait
Copy link

@Hajime-san Yeah, after debugging the problem I found the reason, we have (simplified for the problem):

const server = require("@hono/node-server").serve({
  fetch: app.fetch,
});

const listenOptions = this.options.ipc
  ? { path: this.options.ipc }
  : { host: this.options.host, port: this.options.port };

/** @type {S} */
(this.server).listen(listenOptions, () => {
  resolve();
});

and listen doesn't respect listenOptions, i.e. host and port (and based on current implementations that's expected 😕 ), I would say that this is a design api, before serve just return Server and doesn't run it, but now using serve it creates Server and run it

@Hajime-san
Copy link
Author

@alexander-akait
Thank you for looking into the matter.

NOTE: This issue was fixed below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants