Skip to content

client middleware export causes vite-plugin-tanstack-start-create-server-fn to throw error #3180

@thephilippbusch

Description

@thephilippbusch

Which project does this relate to?

Start

Describe the bug

Creating and exporting a client middleware using createMiddleware().client() causes an internal server error with the following message:

Internal server error: createMiddleware must be called with a "use" property!

The bug seems to originate from vite-plugin-tanstack-start-create-server-fn

Full error message:

[vite] Internal server error: createMiddleware must be called with a "use" property!
  Plugin: vite-plugin-tanstack-start-create-server-fn
  File: /.../tanstack-start/app/middleware/logger.ts
      at Object.handleCreateMiddlewareCallExpression [as handleCallExpression] (file:///.../tanstack-start/node_modules/@tanstack/start-vite-plugin/dist/esm/compilers.js:261:11)
      at file:///.../tanstack-start/node_modules/@tanstack/start-vite-plugin/dist/esm/compilers.js:113:40
      at Array.forEach (<anonymous>)
      at file:///.../tanstack-start/node_modules/@tanstack/start-vite-plugin/dist/esm/compilers.js:112:44
      at Array.forEach (<anonymous>)
      at enter (file:///.../tanstack-start/node_modules/@tanstack/start-vite-plugin/dist/esm/compilers.js:111:24)
      at NodePath._call (/.../tanstack-start/node_modules/@babel/traverse/lib/path/context.js:49:20)
      at NodePath.call (/.../tanstack-start/node_modules/@babel/traverse/lib/path/context.js:39:18)
      at NodePath.visit (/.../tanstack-start/node_modules/@babel/traverse/lib/path/context.js:88:31)
      at TraversalContext.visitQueue (/.../tanstack-start/node_modules/@babel/traverse/lib/context.js:90:16)
      at TraversalContext.visitSingle (/.../tanstack-start/node_modules/@babel/traverse/lib/context.js:66:19)
      at TraversalContext.visit (/.../tanstack-start/node_modules/@babel/traverse/lib/context.js:113:19)
      at traverseNode (/.../tanstack-start/node_modules/@babel/traverse/lib/traverse-node.js:22:17)
      at Module.traverse (/.../tanstack-start/node_modules/@babel/traverse/lib/index.js:53:34)
      at compileStartOutput (file:///.../tanstack-start/node_modules/@tanstack/start-vite-plugin/dist/esm/compilers.js:24:9)
      at TransformPluginContext.transform (file:///.../tanstack-start/node_modules/@tanstack/start-vite-plugin/dist/esm/index.js:44:24)
      at EnvironmentPluginContainer.transform (file:///.../tanstack-start/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47224:19)
      at async loadAndTransform (file:///.../tanstack-start/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:41034:27)

Your Example Website or App

https://github.com/thephilippbusch/tanstack-start

Steps to Reproduce the Bug or Issue

  1. Start the server using bun dev
  2. Open the app in a browser on port 3000
  3. See the error

Expected behavior

createMiddleware().client() to work properly

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome (Arc)
  • Runtime: bun

Additional context

I manually setup the project using the Build from Scratch guide from the docs.

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