{"record":{"id":"b1a333c448e8da89","repo":"FuelLabs/fuels-ts","slug":"env-dependency-missing","errorCode":"ENV_DEPENDENCY_MISSING","errorMessage":"Could not find 'crypto' in current browser environment.","messagePattern":"Could not find 'crypto' in current browser environment\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"critical","filePath":"packages/crypto/src/browser/crypto.ts","lineNumber":6,"sourceCode":"import { ErrorCode, FuelError } from '@fuel-ts/errors';\n\nconst { crypto, btoa } = globalThis;\n\nif (!crypto) {\n  throw new FuelError(\n    ErrorCode.ENV_DEPENDENCY_MISSING,\n    `Could not find 'crypto' in current browser environment.`\n  );\n}\n\nif (!btoa) {\n  throw new FuelError(\n    ErrorCode.ENV_DEPENDENCY_MISSING,\n    `Could not find 'btoa' in current browser environment.`\n  );\n}\n\nexport { crypto, btoa };\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/crypto/src/browser/crypto.ts#L1-L20","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before importing the browser crypto module, verify Web Crypto availability\nif (typeof globalThis !== 'undefined' && !globalThis.crypto) {\n  throw new Error('Web Crypto API is not available. Ensure you are in a secure context (HTTPS or localhost).');\n}\n// Only then import the browser crypto entry\nimport '@fuel-ts/crypto/browser';","typeGuard":"function hasWebCrypto(): boolean {\n  return typeof globalThis !== 'undefined' &&\n    'crypto' in globalThis &&\n    'subtle' in globalThis.crypto;\n}","tryCatchPattern":"// This error is thrown at module load time, not at function call time.\n// To guard against it, check the environment BEFORE importing:\nfunction loadCryptoSafely() {\n  if (!globalThis.crypto) {\n    throw new Error('Web Crypto API unavailable; run in a secure context (HTTPS/localhost)');\n  }\n  // Dynamic import after validation\n  return import('@fuel-ts/crypto/browser');\n}","preventionTips":["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."],"tags":["crypto","browser","environment","web-crypto","secure-context","module-load"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}