I've downloaded d3 from here: https://cdnjs.cloudflare.com/ajax/libs/d3/5.16.0/d3.js and have included it in my /static folder.
/static/graph.js
import * as d3 from "/static/d3.js"
export function graph() {
d3.select("#classname");
console.log("Selected");
}
index.html
<html>
<body>
<script type="module">
import {graph} from "/static/graph.js"
graph()
</script>
</body>
</html>
But, I recieve the error d3.select is not a function.
- The setup of the
/staticfolder is sound; if I change the string referencing either of the .js files, I'm (appropriately) met with aTypeError: Error resolving module specifier: ...That is, with the strings as they are, we can see and serve the files appropriately (further: the response from the network is 304, indicating the cached files match what the server is serving). - D3 is being loaded in some way. If I place a
debugger;inside of thegraph()function, go to the dev. console and typed3, I am able to scroll through an autocomplete list of all functions defined in D3 (includingselect). But, something liked3.select, returnsUndefined. So D3 is being loaded enough to autocomplete, but everything is coming up as undefined. The variable itself is of typeSymbol(Symbol.toStringTag): "Module"which is documented here (though I am not sure what to make of said documentation) - On the other hand, placing a
debugger;statement inindex.htmlshows thatd3seems to work as intended, even though this is not where it's being imported.
Why is d3.select not a function?