ChristopherKRad

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 :heart:

Most Liked

03juan

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

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. :thinking:

03juan

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.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement