Troubleshooting: Why doesn't my ThreeJS installation work properly in Laravel?
P粉811329034
P粉811329034 2024-03-28 18:20:16
0
1
656

First of all, I know that Laravel is a PHP framework and has nothing to do with the front-end (JavaScript) of my application. But laravel offers the possibility to use webpack which can be used for node modules and other javascript stuff if I do it right..

What I've done so far:

Install ThreeJS using the command:

npm install three

Than execution

npm run dev

After that, I included the Library in the app.js file in the Laravel resources folder like this:

var THREE = require('three');

(I tried including it without assigning it to a variable, but that didn't seem to work, so I just did what some google research told me)

I ran npm run dev again and the library was included in the packaged app.js in the project's public/js/ path. Everything seems fine. I included the app.js file in the view and set the script attribute type to module. But now when I try to import Threejs via import * as THREE from '三';

In my case it says the module cannot be found. I know I can copy the contents of ThreeJS in the node_modules folder to my public path JS folder, but I want to keep it as a node module. Any suggestions?

P粉811329034
P粉811329034

reply all(1)
P粉691958181

I'm feeling super stupid right now, but adding a window.THREE instead of var Three somehow solved the problem.. Anyway, thanks for your help and time!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template