I am really struggling with getting D3.js working in my Phoenix app. I have a default Phoenix umbrella app with webpack.
Steps that I have done so far:
Added "d3": ">=5.9.1" to my assets/package.json
Added import "d3" to my assets/js/app.js
Confirmed that the app.js that is loaded in the browser does indeed contain the d3 library.
But no matter what I seem to do every time I try to use d3 I get:
ReferenceError: d3 is not defined
I’m not a web developer. Phoenix generally has been easy enough to figure out because I am pretty good with Elixir, but I am having a really hard time getting this javascript stuff to work. Are my above steps correct? What else am I supposed to be doing?
I have looked through the d3 code, and it does not assign the d3 variable anywhere. I can search for d3 = or with regex d3\s*= but I get nothing. Maybe this is why the import is not working? Maybe a different import method is required?
I didn’t test it with D3, but should work. Have in mind that D3 is a heavy dependency, so splitting your JavaScript files in smaller chunks should help to build a better experience for your users.
^C
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
a
d3jsDemo $ cd assets
assets $ npm i d3 -D
npm WARN assets No description
+ d3@5.9.2
added 33 packages from 1 contributor and audited 14506 packages in 7.422s
found 2 low severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
assets $