Skip to content

Conversation

@lars-hagen
Copy link
Contributor

@lars-hagen lars-hagen commented Sep 12, 2025

Summary

This PR addresses the Turbopack middleware crash issue with code-inspector plugin.

  • Changes default pattern from **/*.{jsx,tsx,js,ts,mjs,mts} to **/app/**/*.{jsx,tsx,js,ts,mjs,mts}
  • Restricts code-inspector to only process files in app directories
  • Naturally excludes middleware files (typically at root/src level), preventing Turbopack crashes

Related Issues

Configuration Workaround

Users can also fix this issue immediately in their next.config.ts without waiting for this PR:

const nextConfig: NextConfig = {
  turbopack: {
    rules: {
      '**/app/**/*.{jsx,tsx,js,ts,mjs,mts}': Object.values(codeInspectorPlugin({ bundler: 'turbopack' }))[0]
    } as any
  },
};

Test Plan

  • Tested with Next.js 15 demo app containing middleware
  • No crashes with middleware present
  • Code inspector works correctly for app directory files

This is a temporary workaround until Turbopack resolves the underlying issue.

@lars-hagen
Copy link
Contributor Author

🎉 Configuration-Level Workaround Available!

While testing this PR, I discovered users can fix this issue immediately without any package changes!

Immediate fix

Add this to your next.config.ts:

import { codeInspectorPlugin } from 'code-inspector-plugin';
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  turbopack: {
    rules: {
      '**/app/**/*.{jsx,tsx,js,ts,mjs,mts}': Object.values(codeInspectorPlugin({ bundler: 'turbopack' }))[0]
    } as any
  },
};

export default nextConfig;

You can customize the pattern to match your project structure (e.g., **/src/**/*.{jsx,tsx}, etc.).

About this PR

While the config workaround solves the immediate problem, this PR could still add value by providing a better out-of-the-box experience. However, I wanted to share this workaround for anyone who needs a fix right now!

Related issues:

@lars-hagen lars-hagen force-pushed the fix/turbopack-default-pattern branch from 6850209 to 3ac00fe Compare September 15, 2025 08:22
Copy link
Owner

@zh-lx zh-lx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks very much!

@zh-lx zh-lx merged commit 1838227 into zh-lx:main Sep 15, 2025
1 check passed
@lars-hagen
Copy link
Contributor Author

Hi @zh-lx! Thanks for merging this PR. After testing with real Next.js 15 projects, I found the current pattern **/app/** misses common directories like components, lib, hooks, etc.

I'd like to propose a follow-up PR with this improved pattern:

'**/*.{jsx,tsx,js,mjs,mts}'

Why this is better:

  • Covers the entire codebase (not just /app)
  • Naturally excludes middleware.ts since .ts files don't contain JSX
  • Aligns perfectly with code-inspector's purpose (JSX element inspection)
  • Much simpler and more intuitive

Since code-inspector adds click-to-source functionality to JSX elements, excluding .ts files makes perfect sense - they're typically utility/config files without JSX.

What do you think? Happy to submit a follow-up PR!

@zh-lx
Copy link
Owner

zh-lx commented Sep 15, 2025

@lars-hagen Thank you for your follow-up and supplementation.
Since maybe middleware is middleware.js, I think it is safer to only do it for . jsx and .tsx. But according to nextjs routing files, some jsx files may also be . js files, so I added a PR: #399

@lars-hagen
Copy link
Contributor Author

lars-hagen commented Sep 15, 2025

@zh-lx Thanks for the quick reply!
I agree I think the best pattern for now is also **/*.{jsx,tsx}.

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

Successfully merging this pull request may close these issues.

2 participants