ReferenceError: Cannot access 'ManagementError' before initialization

Open
#1,434 0 comments 3 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, devtools

Research direction

Start with the generated ManagementTimeoutError.ts and the errors barrel it imports, then check how Fern generates this file and how the ESM build is produced. Reproduce the import failure without creating an Auth0 client or making a network request. Done when the generated error imports ManagementError directly, the cycle is removed, and importing the ESM build succeeds while public exports remain intact.

Written by the indexing model from the issue text.

Description

bug
Checklist
  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.
Description

ESM import can access ManagementError before initialization

Summary

Importing the ESM build can fail during module initialization with:

ReferenceError: Cannot access 'ManagementError' before initialization
    at .../auth0/dist/esm/management/errors/ManagementTimeoutError.mjs:3:52

The failure occurs before an Auth0 client is instantiated or a network request is made, so no Auth0 credentials are required to investigate it.

Suspected cause

ManagementTimeoutError imports the errors barrel and extends its ManagementError export:

import * as errors from "./index.js";

export class ManagementTimeoutError extends errors.ManagementError {}

The barrel also exports ManagementTimeoutError, producing this cycle:

ManagementTimeoutError -> errors/index -> ManagementTimeoutError

Proposed generator change

Generate a direct dependency on the base error instead:

import { ManagementError } from "./ManagementError.js";

export class ManagementTimeoutError extends ManagementError {}

This removes the error module's barrel cycle while preserving the package's public exports.

Notes for maintainers

ManagementTimeoutError.ts is generated by Fern so I didn't create a PR in this repo for it, not sure how that is typically handled.

Reproduction

I ran into this with a simple import in an ESM project -- happy to create a repro repository if needed.

Additional context

No response

node-auth0 version

7.6.0

Node.js version

26.12

Dominant language
TypeScript
Stars
683
Forks
319
Avg merge
1d 30m
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/node-auth0

All issues in auth0/node-auth0

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.