Context
- A problem has arisen with JavaScript when trying to use the topojson.feature(topology, object) function. It seems that this issue appeared after moving from TopoJSON version 1.6.26 to version 2.x, although the functionality remains similar.
- The project uses webpack for production builds and webpack-dev-server for local development.
- Previously, everything was functioning properly without any issues.
Issue
relevant_page.js:705 Uncaught TypeError: Cannot read property 'feature' of undefined
Code Snippets
package.json:
...
"dependencies": {
...
"topojson": "^1.6.26",
relevant_page.js:
import topojson from topojson;
...
function ready(data) {
var topojsonStates = topojson.feature(us, us.objects.states).features;
Troubleshooting Steps
To investigate the error, a breakpoint was set in the browser at the line causing the issue:
var topojsonStates = _topojson2.default.feature(us, us.objects.states).features;
The following elements were inspected:
us: Object
...
type: "Topology"
us.objects.states: Object
...
type: "Topology"
_topojson2.default: undefined
_topojson2.feature(us, us.objects.states).features: Array[53]
The fact that _topojson2.default
is undefined while _topojson2.feature
works presents a confusing situation. Any insights on this matter would be appreciated?
Additional Information
This query is different from discussions around using an npm package with ES6 modules via webpack, as the primary concern here is resolving the Uncaught TypeError. Suggestions on how to enhance the question or answer for better searchability are welcome.