Skip to content

Turbopack: ReferenceError "Cannot access 'globalThis' before initialization" with OpenPGP.js static import #82632

@tnunamak

Description

@tnunamak

Link to the code that reproduces this issue

https://github.com/tnunamak/turbopack-openpgp-repro

To Reproduce

  1. Clone https://github.com/tnunamak/turbopack-openpgp-repro
  2. npm install
  3. npm run dev
  4. Visit http://localhost:3000/api/test - Works
  5. npm run dev:turbo
  6. Visit http://localhost:3000/api/test - Fails

Current vs. Expected behavior

Current Behavior

Static imports of OpenPGP.js fail with Turbopack but work with webpack.

  ReferenceError: Cannot access 'globalThis' before initialization
      at [project]/app/api/test/route.ts [app-route] (ecmascript) (app/api/test/route.ts:2:0)

Expected Behavior

Static imports should work with Turbopack as they do with webpack, since:

  • OpenPGP.js docs show static imports as the standard usage
  • globalThis is a standard ES2020 feature
  • Works in Node.js, webpack, and other bundlers

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #27-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 17:01:58 UTC 2025
  Available memory (MB): 127934
  Available CPU cores: 24
Binaries:
  Node: 24.3.0
  npm: 11.4.2
  Yarn: N/A
  pnpm: 10.13.1
Relevant Packages:
  next: 15.4.6 // Latest available version is detected (15.4.6).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.9.2
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)

Additional context

No response

PACK-5256

Metadata

Metadata

Assignees

Labels

TurbopackRelated to Turbopack with Next.js.linear: turbopackConfirmed issue that is tracked by the Turbopack team.locked

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions