nolimits4web/swiper · warning
text
Error message
text
What it means
showWarning (src/shared/utils.ts:147-153) is Swiper's single warning funnel: every loop/grid advisory string is passed to console.warn(text) at line 149. The body is wrapped in try { ... } catch { /* err */ }, so if console is missing or console.warn throws, the warning is silently swallowed with no re-throw and no fallback channel. This makes the function an observability choke point: the other four warnings in this batch (and all Swiper runtime advisories) surface only if console.warn is actually callable in the host environment.
Source
Thrown at src/shared/utils.ts:149
: []),
);
}
return false;
}
export function elementIsChildOf(el: Element, parent: Element): boolean {
let isChild = parent.contains(el);
if (!isChild && parent instanceof HTMLSlotElement) {
const children = [...parent.assignedElements()];
isChild = children.includes(el);
if (!isChild) isChild = elementIsChildOfSlot(el, parent);
}
return isChild;
}
export function showWarning(text: string): void {
try {
console.warn(text);
} catch {
// err
}
}
export function createElement<K extends keyof HTMLElementTagNameMap>(
tag: K,
classes?: string | string[],
): HTMLElementTagNameMap[K];
export function createElement(tag: string, classes?: string | string[]): HTMLElement;
export function createElement(tag: string, classes: string | string[] = []): HTMLElement {
const el = document.createElement(tag);
el.classList.add(...(Array.isArray(classes) ? classes : classesToTokens(classes)));
return el;
}
// Viewport-relative on purpose: every caller either compares against viewport quantities
// or adds window.scrollX/Y itself, so folding the scroll offset in here double-counts.View on GitHub (pinned to 6138c2a685)
Solutions
- Do not delete, null, or reassign console.warn to a throwing function in any environment where Swiper runs; if you must silence noise, filter by message prefix instead of throwing.
- If running in SSR/Node, ensure globalThis.console is a real console (e.g. keep Node's default) or polyfill console.warn before constructing the Swiper instance.
- To capture Swiper warnings deterministically, wrap console.warn before new Swiper(...) and forward matching messages, since the internal try/catch will otherwise swallow failures.
- Treat Swiper warnings as config defects: fix the upstream loop/grid config (see errors 1-4) so showWarning is never called, rather than relying on console visibility.
Example fix
// before -- Swiper warnings go to console.warn and may be swallowed by showWarning's try/catch
const swiper = new Swiper(el, { loop: true });
// after -- intercept console.warn before init to capture every Swiper advisory
const captured: string[] = [];
const origWarn = console.warn.bind(console);
console.warn = (m: unknown) => {
if (typeof m === 'string' && m.startsWith('Swiper')) captured.push(m);
origWarn(m);
};
const swiper = new Swiper(el, { loop: true }); Defensive patterns
Strategy: validation
Validate before calling
// Run once, before any Swiper instance is created, to ensure warnings can surface
function ensureSwiperConsole(): void {
const g = globalThis as { console?: Partial<Console> };
if (typeof g.console?.warn !== 'function') {
g.console = {
...(g.console ?? {}),
warn: (m?: unknown) => process.stderr.write(String(m ?? '') + '\n'),
} as Console;
}
}
ensureSwiperConsole(); Type guard
function hasWarnableConsole(c: unknown): c is Console & { warn: (m?: unknown) => void } {
return typeof c === 'object' && c !== null && typeof (c as Console).warn === 'function';
} Try / catch
// showWarning swallows internally, so intercept BEFORE it runs
const swiperWarnings: string[] = [];
const origWarn = console.warn.bind(console);
console.warn = (m?: unknown) => {
if (typeof m === 'string' && m.startsWith('Swiper')) swiperWarnings.push(m);
origWarn(m);
};
try {
const swiper = new Swiper(el, params);
} finally {
console.warn = origWarn; // restore
} Prevention
- Never delete/null console.warn or stub it to throw in environments where Swiper runs; filter by message prefix instead.
- In SSR or test setups, assert typeof globalThis.console?.warn === 'function' before constructing Swiper.
- Capture warnings via a console.warn hook rather than relying on showWarning's internal try/catch, which is silent.
- Treat any Swiper warning as a config defect and fix the triggering condition so showWarning is never called.
When it happens
Trigger: console.warn(text) is invoked with any Swiper advisory (e.g. a loop warning). The catch block executes only when the host cannot warn: console is undefined (some SSR/node setups without a console polyfill), console.warn has been deleted or reassigned to a throwing stub, a sandboxed iframe restricts the console, or CSP/lockdown config makes console.warn throw. In a normal browser the call succeeds and the string is printed as a console warning.
Common situations: Server-side rendering where globalThis.console is absent or shimmed; unit tests that stub console.warn to throw on noise; iframe sandboxes (allow-scripts without a full console); CI pipelines that fail on any console.warn where the silent catch then hides which advisory fired; overridden/monkey-patched consoles in analytics-heavy apps.
AI-assisted analysis of nolimits4web/swiper@6138c2a685 (2026-08-12).
Data as JSON: /api/errors/9f1b95548c7b3181.
Report an issue: GitHub.