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

Error when using express as dev server middleware #102

Open
q1uxu opened this issue Jan 6, 2025 · 1 comment
Open

Error when using express as dev server middleware #102

q1uxu opened this issue Jan 6, 2025 · 1 comment

Comments

@q1uxu
Copy link

q1uxu commented Jan 6, 2025

Describe the bug

I use a express app as vite dev server middleware. When visit the website, vite dev server exit with error.

Reproduction

https://github.com/q1uxu/vite-mkcert-configureServer

steps:

  1. init a vite project
  2. install and use vite-plugin-mkcert
  3. install express, make a simple express app, use as a vite dev server middleware
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import mkcert from "vite-plugin-mkcert";
import expressApp from "./server";

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react(),
    mkcert(),
    {
      name: "vite-plugin-express",
      configureServer(server) {
        server.middlewares.use(expressApp);
      },
    },
  ],
});
// server/index.ts
import express from "express";

const app = express();

app.get("/api/ping", (req, res) => {
  res.status(200).end("ping");
});

export default app;
  1. curl https://localhost:5173/

result:

var path = parseUrl$1(req).pathname || '/';
                          ^

TypeError: Cannot read properties of undefined (reading 'pathname')

System Info

Output of npx envinfo --system --npmPackages vite,vite-plugin-mkcert --binaries --browsers:

System:
  OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
  CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  Memory: 8.21 GB / 11.36 GB
  Container: Yes
  Shell: 5.8 - /usr/bin/zsh
Binaries:
  Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v22.12.0/bin/yarn
  npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
  pnpm: 9.12.2 - ~/.local/share/pnpm/pnpm
  bun: 1.1.40 - ~/.bun/bin/bun

Used package manager:

pnpm

Logs

file:///tmp/vite-project/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:22512
    var path = parseUrl$1(req).pathname || '/';
                              ^

TypeError: Cannot read properties of undefined (reading 'pathname')
    at next (file:///tmp/vite-project/node_modules/.pnpm/vite@6.0.7_@types+node@22.10.5/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:22512:31)
    at call (file:///tmp/vite-project/node_modules/.pnpm/vite@6.0.7_@types+node@22.10.5/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:22604:3)
    at next (file:///tmp/vite-project/node_modules/.pnpm/vite@6.0.7_@types+node@22.10.5/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:22539:5)
    at Function.handle (file:///tmp/vite-project/node_modules/.pnpm/vite@6.0.7_@types+node@22.10.5/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:22542:3)
    at Http2SecureServer.app (file:///tmp/vite-project/node_modules/.pnpm/vite@6.0.7_@types+node@22.10.5/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:22407:37)
    at Http2SecureServer.emit (node:events:524:28)
    at Http2SecureServer.onServerStream (node:internal/http2/compat:974:10)
    at Http2SecureServer.emit (node:events:524:28)
    at ServerHttp2Session.sessionOnStream (node:internal/http2/core:3014:19)
    at ServerHttp2Session.emit (node:events:524:28)

Node.js v22.12.0

@q1uxu q1uxu changed the title Error when using express middleware by vite configureServer Error when using express as dev server middleware Jan 6, 2025
@liuweiGL
Copy link
Owner

liuweiGL commented Jan 8, 2025

If I replace the plugin with the official vite-plugin-basic-ssl the same error occurs. So, it seems that there is an issue with the integration method of Express.

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