plotly/plotly.js · warning
Invalid GeoJSON type ${type}. Traces with locationmode *geoj
Error message
Invalid GeoJSON type ${type}. Traces with locationmode *geojson-id* only support *FeatureCollection* and *Feature* types. What it means
For traces with locationmode 'geojson-id', plotly.js extracts GeoJSON features to match location ids. Only GeoJSON objects of type 'FeatureCollection' or 'Feature' are supported; anything else (Geometry, GeometryCollection, FeatureCollection-ish malformed input, or missing type) triggers this warning and the trace gets no geometry.
Source
Thrown at src/lib/geo_location_utils.js:289
}
// remove key from lookup, so that we can track (if any)
// the locations that did not have a corresponding GeoJSON feature
delete lookup[id];
}
switch (geojsonIn.type) {
case 'FeatureCollection':
var featuresIn = geojsonIn.features;
for (i = 0; i < featuresIn.length; i++) {
appendFeature(featuresIn[i]);
}
break;
case 'Feature':
appendFeature(geojsonIn);
break;
default:
loggers.warn(
[
'Invalid GeoJSON type',
(geojsonIn.type || 'none') + '.',
'Traces with locationmode *geojson-id* only support',
'*FeatureCollection* and *Feature* types.'
].join(' ')
);
return false;
}
for (var loc in lookup) {
loggers.log(
[
'Location *' + loc + '*',
'does not have a matching feature with id-key',
'*' + trace.featureidkey + '*.'
].join(' ')
);View on GitHub (pinned to 1d090e0b5f)
Solutions
- Wrap raw geometries: {type: 'Feature', geometry: <your geometry>, properties: {}} before assigning to geojson.
- Convert TopoJSON to GeoJSON (e.g. with topojson-client feature()) before use.
- Verify geojson.type === 'FeatureCollection' || geojson.type === 'Feature' right after fetching.
- Ensure features contain an id (or use featureidkey pointing to a properties field) so 'geojson-id' lookups resolve.
- Log JSON.parse of your file and inspect the top-level type when the warning appears.
Example fix
// before
Plotly.newPlot(gd, [{type: 'choropleth', locationmode: 'geojson-id', geojson: {type: 'Polygon', coordinates: [...]}}]);
// after
const feature = {type: 'Feature', properties: {id: 'ABC'}, geometry: {type: 'Polygon', coordinates: [...]}};
Plotly.newPlot(gd, [{type: 'choropleth', locationmode: 'geojson-id', geojson: feature, locations: ['ABC'], featureidkey: 'properties.id'}]); Defensive patterns
Strategy: validation
Validate before calling
function isUsableGeoJSON(g) {
return !!g && (g.type === 'FeatureCollection' || g.type === 'Feature') &&
(g.type === 'FeatureCollection' ? Array.isArray(g.features) && g.features.length > 0 : !!g.geometry);
}
if (!isUsableGeoJSON(geojson)) throw new Error('geojson must be Feature or FeatureCollection'); Type guard
function isGeoJSONFeatureOrCollection(v) {
return typeof v === 'object' && v !== null &&
(v.type === 'Feature' || (v.type === 'FeatureCollection' && Array.isArray(v.features)));
} Try / catch
const res = await fetch(url);
const geojson = await res.json();
if (!isGeoJSONFeatureOrCollection(geojson)) {
throw new Error(`expected Feature/FeatureCollection, got ${geojson && geojson.type}`);
}
Plotly.newPlot(gd, [{type: 'choropleth', locationmode: 'geojson-id', geojson, ...}]); Prevention
- Convert TopoJSON with topojson-client before use.
- Wrap bare geometries in {type:'Feature', geometry, properties}.
- Give features ids or set featureidkey to a properties field.
- Verify the fetched endpoint actually returns GeoJSON, not TopoJSON or shapefile output.
When it happens
Trigger: Passing a raw Geometry ({type: 'Polygon', ...}) or an array of geometries as the geojson attribute; a fetched TopoJSON or non-GeoJSON file; a geojson object whose .type is misspelled or absent; passing a Feature collection wrapped in another object.
Common situations: Using data exported from shapefile converters that emit bare geometries; fetching 'GeoJSON' endpoints that actually return TopoJSON; building geojson by hand and forgetting the Feature wrapper; version confusion after switching locationmode from 'geojson' to 'geojson-id'.
Related errors
AI-assisted analysis of plotly/plotly.js@1d090e0b5f (2026-09-02).
Data as JSON: /api/errors/115763d971913b80.
Report an issue: GitHub.