Skip to content

fix: run billing:usage's main() after its lookup tables initialize - #162

Open
mattbalza wants to merge 1 commit into
every-app:mainfrom
mattbalza:fix/billing-usage-tdz
Open

fix: run billing:usage's main() after its lookup tables initialize#162
mattbalza wants to merge 1 commit into
every-app:mainfrom
mattbalza:fix/billing-usage-tdz

Conversation

@mattbalza

Copy link
Copy Markdown

ReferenceError: Cannot access 'main' before initialization

pnpm billing:usage fails on every run today:

file:///.../scripts/dataforseo-account-usage.ts:10
await main();
      ^
ReferenceError: Cannot access 'main' before initialization

await main() sits at line 10, above the const price and endpoint tables the
function reads. main is a function declaration so it hoists, but those const
bindings stay in their temporal dead zone until the module finishes evaluating —
so the call is guaranteed to throw, not merely fragile.

The fix

Move the call to the end of the module. The script has no other entry point and
nothing after it depends on ordering, so this is the entire change.

Test plan

pnpm billing:usage           # prints the account summary instead of throwing
pnpm billing:usage --json=true

Both hit only the free GET /v3/appendix/user_data endpoint, so verifying costs
nothing.

`pnpm billing:usage` throws `ReferenceError: Cannot access 'main' before
initialization` on every run today. The call sits at line 10, above the
`const` price and endpoint tables the function reads: `main` itself hoists,
but those bindings are in their temporal dead zone until the module finishes
evaluating.

Moving the call to the end of the module is the whole fix — the script has no
other entry point, and nothing after it depends on ordering.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant