apache/echarts · error
Invalid geoJson format {}
Error message
Invalid geoJson format
{} What it means
Runtime (NOT dev-only) error in GeoJSONResource._parseToRegions: when registering a GeoJSON map via echarts.registerMap, the JSON is parsed into regions by parseGeoJson. If parseGeoJson throws (malformed GeoJSON structure, unsupported geometry type, missing coordinates), the error message is wrapped and re-thrown as 'Invalid geoJson format'. Fires in production.
Source
Thrown at src/coord/geo/GeoJSONResource.ts:107
return {
regions: finalRegions,
boundingRect: parsed.boundingRect || new BoundingRect(0, 0, 0, 0),
regionsMap: regionsMap
};
}
private _parseToRegions(nameProperty: string): GeoJSONRegion[] {
const mapName = this._mapName;
const geoJSON = this._geoJSON;
let rawRegions;
// https://jsperf.com/try-catch-performance-overhead
try {
rawRegions = geoJSON ? parseGeoJson(geoJSON, nameProperty) : [];
}
catch (e) {
throw new Error('Invalid geoJson format\n' + e.message);
}
fixNanhai(mapName, rawRegions);
each(rawRegions, function (region) {
const regionName = region.name;
fixTextCoord(mapName, region);
fixDiaoyuIsland(mapName, region);
// Some area like Alaska in USA map needs to be tansformed
// to look better
const specialArea = this._specialAreas && this._specialAreas[regionName];
if (specialArea) {
region.transformTo(
specialArea.left, specialArea.top, specialArea.width, specialArea.height
);
}View on GitHub (pinned to 30076aedcd)
Solutions
- Validate the GeoJSON with a linter (geojsonlint.com or a library like @turf/helpers) before registerMap
- Use an authoritative map source (e.g. the echarts map repo)
- Convert TopoJSON to GeoJSON (topojson-client featurecollection) first
Example fix
// before
echarts.registerMap('foo', brokenOrTopoJson);
// after
echarts.registerMap('foo', validatedGeoJsonFeatureCollection); Defensive patterns
Strategy: try-catch
Validate before calling
function isFeatureCollection(v: any): boolean {
return v && v.type === 'FeatureCollection' && Array.isArray(v.features)
&& v.features.every((f: any) => f && f.type === 'Feature' && f.geometry);
}
if (!isFeatureCollection(geo)) throw new Error('input is not a valid GeoJSON FeatureCollection'); Type guard
const isFeatureCollection = (v: any): v is GeoJSON.FeatureCollection => v != null && v.type === 'FeatureCollection' && Array.isArray(v.features);
Try / catch
try {
echarts.registerMap('foo', geo);
} catch (e) {
if (/geoJson/i.test((e as Error).message)) {
console.error('map registration failed; GeoJSON is malformed', e);
} else {
throw e;
}
} Prevention
- Lint GeoJSON (geojsonlint.com or @turf) before registerMap
- Use canonical map sources rather than hand-edited files
- Convert TopoJSON to GeoJSON before registering
When it happens
Trigger: Passing malformed GeoJSON (wrong feature/geometry type, missing coordinates array, invalid structure) to echarts.registerMap; truncated or corrupted map JSON; passing TopoJSON instead of GeoJSON.
Common situations: Hand-edited GeoJSON; down-sampled/corrupted map file; wrong format (TopoJSON); GeoJSON produced by a non-conformant exporter.
Related errors
- Sankey is a DAG, the original data has cycle!
- BMap api is not loaded
- Only one bmap component can exist
- Data view format error {}
AI-assisted analysis of apache/echarts@30076aedcd (2026-08-12).
Data as JSON: /api/errors/378baa8825587987.
Report an issue: GitHub.