mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #583] vinext check should flag __dirname/__filename and suggest ESM path APIs #125
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#125
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @southpolesteve on GitHub (Mar 18, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/583
Summary
vinext checkshould detect server-side uses of__dirname/__filenameand tell users to migrate to an ESM-native path pattern.Real-world case
This came up while testing the Platformatic Watt demo app (
ecommercebranch):That file uses
__dirnameto search for the app'sdata/directory:The app works under Next.js, but this usage was the actual blocker under vinext/Vite SSR.
vinext checkdid not flag it, so the compatibility report missed the real runtime risk.Why this should be checked
__dirname/__filenameare CommonJS globals, not ESM globals. Since vinext runs server modules through a Vite/ESM pipeline, these identifiers are a migration hazard even in otherwise normal Node-targeted server code.This is not a Cloudflare-specific problem. It is a general Vite/ESM compatibility issue that users are likely to hit when migrating existing Next.js apps.
Proposed behavior
When
vinext checkscans app/server code and finds free uses of__dirnameor__filename, report a warning with a migration hint.Suggested guidance:
__dirname/__filenamefileURLToPath(import.meta.url)+dirname(...)import.meta.dirname/import.meta.filenameare also availableExample warning text:
Why this matters
Even if vinext adds more runtime compatibility here, the check command should still surface legacy CJS path usage and steer users toward the ESM-native pattern up front.