Skip to content

Conversation

kylemurray2
Copy link

The CLI was crashing with a ReferenceError: document is not defined because it was trying to execute browser-specific code for authentication.

This change introduces an environment check using detect-node to prevent browser-only code from running in the Node.js environment.

  • In src/file.ts, the getApiAuthNetwork function now throws an error when called in Node.js, as it relies on browser APIs.
  • The getSuffix function is also made safe for Node.js execution.
  • In src/cli.ts, a try...catch block is added to the download logic to gracefully handle the error thrown by getApiAuthNetwork and other potential download errors. This prevents the application from crashing and provides a user-friendly error message.

The CLI was crashing with a `ReferenceError: document is not defined`
because it was trying to execute browser-specific code for authentication.

This change introduces an environment check using `detect-node` to
prevent browser-only code from running in the Node.js environment.

- In `src/file.ts`, the `getApiAuthNetwork` function now throws an error
  when called in Node.js, as it relies on browser APIs.
- The `getSuffix` function is also made safe for Node.js execution.
- In `src/cli.ts`, a `try...catch` block is added to the download logic
  to gracefully handle the error thrown by `getApiAuthNetwork` and
  other potential download errors. This prevents the application from
  crashing and provides a user-friendly error message.
@kylemurray2 kylemurray2 closed this Sep 4, 2025
@kylemurray2 kylemurray2 reopened this Sep 4, 2025
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