Skip to content

__dirname is /ROOT/... instead of real path in Turbopack #86476

@FabianKoder

Description

@FabianKoder

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/angry-lalande-98zyn5

To Reproduce

  1. require() a cjs module, for example in getServerSideProps or in a server component. Import location does not matter.
  2. Inside of the module, try to access __dirname - it is /ROOT/... instead of the real path. import.meta.url works correctly though - this is not a valid workaround though, since this normally does not work in CommonJS.

Current vs. Expected behavior

__dirname should work the same as when using Webpack / be consistent with data reported from import.meta

Provide environment information

Node: 20.12.1
  npm: 10.5.0
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 16.0.2-canary.34 // Latest available version is detected (16.0.2-canary.34).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TurbopackRelated to Turbopack with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions