diff --git a/src/index.ts b/src/index.ts index 4e4a6e1..a7b79de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,7 +78,10 @@ export function beforeRemote(fn: Handler): void { export function remoteForm(selector: string, fn: RemoteFormHandler): void { if (!formHandlers) { formHandlers = new Map() - document.addEventListener('submit', handleSubmit) + + if (typeof document !== 'undefined') { + document.addEventListener('submit', handleSubmit) + } } const handlers = formHandlers.get(selector) || [] formHandlers.set(selector, [...handlers, fn])