Registry / devops / dom-exception-modern

dom-exception-modern

JSON →
library0.1.0jsnpmunverified

A zero-dependency migration helper for replacing the deprecated `domexception` package with the native `DOMException` constructor available in modern Node.js (>=18), browsers, and Deno. Version 0.1.0 released in 2025. It default-exports the native DOMException for drop-in compatibility, and provides typed utility functions: `createDOMException`, `isDOMException`, `toDOMException`, and legacy code constants via `domExceptionCodes`. Ships TypeScript declarations. Unlike the legacy `domexception`, this package has no runtime fallback and is intended only for environments where DOMException is natively available.

npm install dom-exception-modern
INSTALL
IMPORT
SIG · DOM-EXCEPTION-MODE
D
dom-exception-modern
devopsjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (DOMException)
import DOMException from 'dom-exception-modern'
import { DOMException } from 'dom-exception-modern'
Default export is the native DOMException constructor. Named import will fail.
isDOMException
import { isDOMException } from 'dom-exception-modern'
import DOMException, { isDOMException } from 'dom-exception-modern'
Named export, works alongside default import.
createDOMException
import { createDOMException } from 'dom-exception-modern'
import createDOMException from 'dom-exception-modern'
Named export, not default.
domExceptionCodes
import { domExceptionCodes } from 'dom-exception-modern'
import domExceptionCodes from 'dom-exception-modern'
Named export providing legacy numeric code constants.

Shows default and named imports, constructor usage, utility helpers, and legacy code constants.

import DOMException, { createDOMException, isDOMException, toDOMException, domExceptionCodes } from 'dom-exception-modern'; // Use as a drop-in replacement for the deprecated 'domexception' const err1 = new DOMException('Custom error', 'NotFoundError'); console.log(err1.name); // 'NotFoundError' console.log(err1.message); // 'Custom error' // Create with utility const err2 = createDOMException('Operation aborted', 'AbortError'); console.log(err2.code); // 20 (AbortError code from legacy mapping) // Check for DOMException console.log(isDOMException(err1)); // true console.log(isDOMException(new Error())); // false // Convert unknown errors const converted = toDOMException('some string error', 'TypeError'); console.log(converted instanceof DOMException); // true // Legacy code constants console.log(domExceptionCodes.ABORT_ERR); // 20
Debug
Known issues
breakingNative DOMException required: Node >=18, modern browsers, Deno. Older environments will throw ReferenceError.
fix
Ensure runtime supports DOMException natively. Use polyfill or stick with legacy 'domexception' for Node <18.
affects: all
deprecatedThis package is intended as a migration path; directly using native DOMException is preferred in new code.
fix
Replace `import DOMException from 'dom-exception-modern'` with `const DOMException = globalThis.DOMException` or just use `DOMException` directly.
affects: all
gotchaDefault export is the native DOMException constructor, not a polyfill. It cannot be instantiated without `new`.
fix
Always use `new DOMException(...)` to create instances.
affects: all
gotcha`domExceptionCodes` object contains legacy numeric codes like `ABORT_ERR: 20`, but these may not match all browser implementations exactly.
fix
Rely on error `name` instead of `code` for cross-platform compatibility.
affects: all
Errors
Common errors & fixes
SyntaxError: The requested module 'dom-exception-modern' does not provide an export named 'DOMException'
Attempting to import 'DOMException' as a named export instead of default import.
fix
Use `import DOMException from 'dom-exception-modern'` (default import) instead of `import { DOMException } from 'dom-exception-modern'`.
ReferenceError: DOMException is not defined
Running in an environment (e.g., Node <18) where native DOMException is not available.
fix
Upgrade Node to >=18 or use a polyfill like `domexception` package.
TypeError: Class constructor DOMException cannot be invoked without 'new'
Calling `DOMException(...)` without the `new` keyword.
fix
Use `new DOMException(...)` to instantiate.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
dom-exception-modern — npm install dom-exception-modern · libregistry