Fix Turbopack 'path.join is very dynamic' Error #393
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Turbopack "path.join is very dynamic" Error
Summary
This PR fixes a bug where code-inspector's existing turbopack support fails when Turbopack applies stricter static analysis, particularly when middleware.ts files are present.
Problem
Code-inspector already has turbopack support, but it breaks in certain scenarios:
Root Cause
The current implementation uses Node.js path APIs (
path.resolve,fileURLToPath) to dynamically locate the webpack loader. In certain scenarios (such as when middleware.ts is present), Turbopack applies stricter static analysis that disallows these dynamic operations.Solution
This PR fixes the issue by:
@code-inspector/turbopack/dist/turbopack-loader.js)Usage
How to Reproduce the Bug
Option A: Create a new app from scratch
next.config.ts:src/middleware.ts:Visit http://localhost:3000 in your browser
Error occurs:
[plugin:webpack-code-inspector-plugin] × Input is not valid: "path.join" is very dynamicOption B: Use the existing demo in this repository
cd demos/turbopack-next15package.jsonto use the published version instead of workspace:Visit http://localhost:3000 in your browser
Error occurs:
[plugin:webpack-code-inspector-plugin] × Input is not valid: "path.join" is very dynamicNote: With this PR's changes (using
workspace:^), the error is fixed and code-inspector works correctly.This error primarily occurs with middleware.ts files, but may happen in other scenarios where Turbopack applies strict static analysis.
Testing
Tested with Next.js 15.5.2 in turbopack mode:
Compatibility