ChristopherKRad
Having some difficulty adding three.js to a Phoenix project
I’m having some difficulty adding the npm package “three” to my phx project.
Specifically, I am getting blank screen on the /3D route that I have set, however, I am getting the hello word. The div seems to be recognized, but I think there may be something wrong with esbuild?
I’ve tried vendoring three.js using the minified link here with no luck either: https://raw.githubusercontent.com/mrdoob/three.js/dev/build/three.min.js
My current config can be found in the image attached.
I am more familiar with Phx Backend than front end, but would still consider myself a beginner - especially as it relates to adding JS deps.
Any help is appreciated ![]()
Most Liked
03juan
Hi Christopher, welcome to the forum.
The screen grab is too low res to see anything, it would be better if you posted the relevant code directly as text.
03juan
Here’s a link to my github repo 03juan/three_cube
My previous answer was actually misleading, sorry about that. I actually got the error after installing the three module from npm into the vendor directory, and then importing from ../vendor/node_modules/three/build/three.min.js, not directly from ../vendor/three.min.js. I assumed that the error would also show in the second case but didn’t check before posting.
Have a look at app.js in the repo. In its current state importing from node_modules I get the error when building the asset, and there is no cube. However using the import in the second line does show the cube, and the console only shows the warning:
Scripts "build/three.js" and "build/three.min.js" are deprecated with r150+, and will be removed with r160. Please use ES Modules or alternatives
I tried to build the bundle with esbuild 0.14.29 used in Phoenix 1.6.13 and that also works when importing three.min.js directly from vendor but not from within node_modules.
Not sure why it works with one but not the other. My guess is something to do with it being a inside node package, but don’t have enough experience with js bundling to really know. ![]()
03juan
This won’t succeed because it returns undefined when the attribute is missing.
However you also will need to add phx-update="ignore" to the element, otherwise your scene will be removed on the next update from the server.
DOM patching & temporary assigns
The “ignore” behaviour is frequently used when you need to integrate with another JS library. Note only the element contents are ignored, its attributes can still be updated.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









