FuelLabs/fuels-ts · critical · FuelError
ENV_DEPENDENCY_MISSING
ENV_DEPENDENCY_MISSING
Error message
Could not find 'crypto' in current browser environment.
What it means
Thrown at module load time (packages/crypto/src/browser/crypto.ts:6) when globalThis.crypto is undefined. This file is part of the browser-specific crypto entry point and destructures crypto and btoa from globalThis at import time. If the Web Crypto API is unavailable, the module cannot function and throws immediately during import — before any function can be called. The same file also checks for btoa and throws ENV_DEPENDENCY_MISSING if that is missing.
Source
Thrown at packages/crypto/src/browser/crypto.ts:6
import { ErrorCode, FuelError } from '@fuel-ts/errors';
const { crypto, btoa } = globalThis;
if (!crypto) {
throw new FuelError(
ErrorCode.ENV_DEPENDENCY_MISSING,
`Could not find 'crypto' in current browser environment.`
);
}
if (!btoa) {
throw new FuelError(
ErrorCode.ENV_DEPENDENCY_MISSING,
`Could not find 'btoa' in current browser environment.`
);
}
export { crypto, btoa };
View on GitHub (pinned to b3f37c91ac)
Solutions
- Ensure the application runs in a secure context: HTTPS or localhost (Web Crypto is only available in secure contexts).
- If running in Node.js, ensure the bundler resolves the Node.js crypto entry, not the browser one.
- Upgrade to a browser that supports the Web Crypto API (all modern browsers since ~2017).
- If in a restricted environment (extension sandbox, iframe), ensure crypto is exposed on globalThis before this module loads.
Defensive patterns
Strategy: validation
Validate before calling
// Before importing the browser crypto module, verify Web Crypto availability
if (typeof globalThis !== 'undefined' && !globalThis.crypto) {
throw new Error('Web Crypto API is not available. Ensure you are in a secure context (HTTPS or localhost).');
}
// Only then import the browser crypto entry
import '@fuel-ts/crypto/browser'; Type guard
function hasWebCrypto(): boolean {
return typeof globalThis !== 'undefined' &&
'crypto' in globalThis &&
'subtle' in globalThis.crypto;
} Try / catch
// This error is thrown at module load time, not at function call time.
// To guard against it, check the environment BEFORE importing:
function loadCryptoSafely() {
if (!globalThis.crypto) {
throw new Error('Web Crypto API unavailable; run in a secure context (HTTPS/localhost)');
}
// Dynamic import after validation
return import('@fuel-ts/crypto/browser');
} Prevention
- Ensure the application runs over HTTPS or on localhost — Web Crypto requires a secure context.
- Verify bundler configuration resolves the correct entry point for the target runtime (browser vs Node.js).
- Check browser compatibility: all modern browsers support Web Crypto, but legacy ones do not.
- In SSR/SSG setups, ensure the browser crypto module is only loaded client-side, not during server rendering.
When it happens
Trigger: Importing the browser crypto module in a runtime that lacks globalThis.crypto: an outdated browser (pre-2017), a non-browser environment misconfigured to load the browser entry point, or a secure context issue (Web Crypto requires HTTPS or localhost). Also triggered by certain bundler/tree-shaking misconfigurations that select the browser entry for a Node.js build.
Common situations: Running in an insecure context (HTTP, not localhost) where window.crypto.subtle is undefined; very old browser without Web Crypto support; SSR or Node.js bundler resolving the browser subpath instead of the Node.js one; browser extension sandbox with restricted globals.
Related errors
- INVALID_CREDENTIALS
- Unsupported platform ${process.platform}.${process.platform
- Unsupported arch ${process.arch}
- Unsupported platform ${process.platform}.${process.platform
- Unsupported arch ${process.arch}
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/b1a333c448e8da89.
Report an issue: GitHub.