:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { isChunkLoadError, isGenericNetworkTypeError, markAsChunkLoadError } from './isChunkLoadError'
describe('isChunkLoadError', () => {
it.each([
['webpack ChunkLoadError', { name: 'ChunkLoadError', message: 'Loading chunk 0 failed.' }, true],
[
'esbuild dynamic-import failure',
{ name: 'TypeError', message: 'Failed to fetch dynamically imported module: /static/chunk.js' },
true,
],
[
'Firefox dynamic-import failure',
{ name: 'TypeError', message: 'error loading dynamically imported module: /static/chunk.js' },
true,
],
[
'WebKit module-script load failure (TypeError)',
{ name: 'TypeError', message: 'Importing a module script failed.' },
true,
],
[
'WebKit module-script load failure (plain Error, not TypeError)',
{ name: 'Error', message: 'Importing a module script failed.' },
true,
],
[
'Chrome unmapped stable chunk specifier',
{
name: 'TypeError',
message:
'Failed to resolve module specifier "@c/c0A1B2C3D4E". Relative references must start with either "/", "./", or "../".',
},
true,
],
[
'Firefox unmapped stable chunk specifier',
{
name: 'TypeError',
message:
'The specifier “@c/c0A1B2C3D4E” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.',
},
true,
],
[
'Safari unmapped stable chunk specifier',
{ name: 'TypeError', message: "Module name, '@c/c0A1B2C3D4E' does not resolve to a valid URL." },
true,
],
[
'unmapped specifier outside the stable chunk build',
{ name: 'TypeError', message: 'Failed to resolve module specifier "lodash".' },
false,
],
['generic TypeError', { name: 'TypeError', message: 'undefined is not a function' }, false],
['unrelated Error', { name: 'Error', message: 'something else' }, false],
['error with no name or message', {}, false],
['Safari native TypeError: Load failed, unmarked', { name: 'TypeError', message: 'Load failed' }, false],
[
'Firefox native TypeError: NetworkError, unmarked',
{ name: 'TypeError', message: 'NetworkError when attempting to fetch resource.' },
false,
],
])('classifies %s', (_label, error, expected) => {
expect(isChunkLoadError(error)).toBe(expected)
})
it.each([
['null', null],
['undefined', undefined],
['string', 'Load failed'],
['number', 42],
])('returns false for non-object %s', (_label, value) => {
expect(isChunkLoadError(value)).toBe(false)
})
it('treats a generic network TypeError as a chunk load error once marked by retryImport', () => {
const error = { name: 'TypeError', message: 'Load failed' }
expect(isChunkLoadError(error)).toBe(false)
markAsChunkLoadError(error)
expect(isChunkLoadError(error)).toBe(true)
})
})
describe('isGenericNetworkTypeError', () => {
it.each([
['Safari native TypeError: Load failed', { name: 'TypeError', message: 'Load failed' }, true],
[
'Firefox native TypeError: NetworkError',
{ name: 'TypeError', message: 'NetworkError when attempting to fetch resource.' },
true,
],
['generic TypeError', { name: 'TypeError', message: 'undefined is not a function' }, false],
['non-TypeError with a matching message', { name: 'Error', message: 'Load failed' }, false],
['error with no name or message', {}, false],
])('classifies %s', (_label, error, expected) => {
expect(isGenericNetworkTypeError(error)).toBe(expected)
})
})