Video Thumbnail

Sign up for a plan to instantly unlock all premium lessons.

UNLOCK LESSON

Premium Features

Download Video

Refactor Into Single Page App

To create a seamless transition into a separate page on our site, we're going to need to use a single page framework like Nuxt or Next.js. Since Nuxt uses Vue, it is by default a much easier framework to use in my opinion, so we'll be going with that.

To get our three.js piece working in Nuxt, we need to do quite a bit of refactoring, mainly because Nuxt renders its HTML on the server side of things for enhanced performance and SEO. It's a bit of extra work, but by doing so, we'll be able to utilize Nuxt's wonderful routing system that'll load only the exact content we need without ever having to do a full page refresh.

Follow along and let me guide you through the complete refactor process to get three.js working in a real-world project.

Comments

Want to participate?

Create a free Chris Courses account to begin

Login
T
ThoughtWolf posted 2 years ago

dat.gui can no longer be imported in Nuxt with version 3.11.2. How else could I import it? I still have the same "window is not defined" with the import * as dat from "dat.gui". But will also get "require is not defined" if I try the const dat = require("dat.gui").

0
H
HarryQuasar posted 2 years ago
PS E:\learning\Web Dev\HTML\Chris Course\firstthreejs> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: orbit-controls-es6@2.0.1
npm ERR! Found: three@0.160.1
npm ERR! node_modules/three
npm ERR!   dev three@"^0.160.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer three@"0.108.0" from orbit-controls-es6@2.0.1
npm ERR! node_modules/orbit-controls-es6
npm ERR!   orbit-controls-es6@"^2.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: three@0.108.0
npm ERR! node_modules/three
npm ERR!   peer three@"0.108.0" from orbit-controls-es6@2.0.1
npm ERR!   node_modules/orbit-controls-es6
npm ERR!     orbit-controls-es6@"^2.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\HKP\AppData\Local\npm-cache\_logs\2024-01-30T16_36_27_684Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: C:\Users\HKP\AppData\Local\npm-cache\_logs\2024-01-30T16_36_27_684Z-debug-0.log

Nuxt is so hard to use

I got this error, and in my website

it said 500

ambiguous indirect export: FlatShading

what should i do the fix it

0
EJTexas posted 3 years ago

2023 UPDATE:

Hello all. Much like others here, I too have had to do some deep diving into this issue. After many hours of trial and error, I finally got this to work properly.

(Start this procedure in /node folder)

Solution – 1

The error comes from the recent Nuxt 3 Release and is being tracked on the create-nuxt-app Github.

Create-nuxt-app is not compatible with Nuxt 3 yet. Therefore, for now, you have to install Nuxt 3 and Tailwind CSS manually:

npx nuxi init <project-name>
cd <project-name>
npm install
npm install @nuxtjs/tailwindcss --save-dev

Now you should be able to run your app as expected:

npm run dev
1
T
Tanner posted 3 years ago

To anyone looking to follow this tutorial in 2023, just know there are many outdated things as well as things he forgot to mention that could make your experience much more difficult - as I have found out myself.

For starters, he does not mention that for create-nuxt-app to work you must have nuxt installed globally on your system. I had to create a vue application and run npm i -g create-nuxt-app in the terminal just for the command to be recognized. Then you will be able to follow the prompts he does to create the app.

The next issue I ran into and have not been able to solve after several hours of attempting is once I created the app and opened it in the text editor, I ran the npm run dev and have ran into more error messages.

Error: error:0308010C:digital envelope routines::unsupported

opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],

library: 'digital envelope routines',

reason: 'unsupported',

code: 'ERR_OSSL_EVP_UNSUPPORTED'

and

   ╭─────────────────────────────────────────────────────────────────────────────────╮
   │                                                                      │
   │   ✖ Nuxt Fatal Error                                                   │
   │                                                                      │
   │   TypeError: Cannot destructure property 'nuxt' of 'this' as it is undefined. │
   │                                                                      │
   ╰─────────────────────────────────────────────────────────────────────────────────╯

And after several hours wasted trying to find out how to fix this and allow me to run the dev server I am now conceding.

Just a warning to be prepared for future viewers.

0
T
Tanner posted 3 years ago

Note: I was able to get the development server to run with nuxt by using the command

NODE_OPTIONS=--openssl-legacy-provider npm run dev

instead of just npm run dev

There is something with the hashing used in webpack that must be outdated or something, I don't know how to explain this one.

0
f
flight505 posted 3 years ago

Hi Chris, Could you explain why three.js newer versions breaks everything? I get a lot of errors related to ES as three.js is treated as an ES module file.

thanks

0
f
flight505 posted 3 years ago

Also I am getting this error with orbit-controls

npm i orbit-controls-es6 --save

npm ERR! code ERESOLVE

npm ERR! ERESOLVE unable to resolve dependency tree

npm ERR!

npm ERR! While resolving: chris_portfolio@1.0.0

npm ERR! Found: three@0.127.0

npm ERR! node_modules/three

npm ERR! three@"^0.127.0" from the root project

npm ERR!

npm ERR! Could not resolve dependency:

npm ERR! peer three@"0.108.0" from orbit-controls-es6@2.0.1

npm ERR! node_modules/orbit-controls-es6

npm ERR! orbit-controls-es6@"*" from the root project

0
chris posted 3 years ago

Hi there, NPM recently updated its package manager to stop certain modules from downloading unless you add the flag --legacy-peer-deps .

Try installing the package with:

npm install orbit-controls-es6 --save --legacy-peer-deps

And I want to say you should be able to install things accordingly. Besides that, Three.js has also made some drastic changes over the past two years which cause certain packages to not work in the same way as displayed in this video. You'll want to use the 0.127.0 version here for sure, but I think me taking some time to show how to upgrade to newer versions would be helpful as well. Sorry for the inconvenience!

0
g
gjhammt posted 3 years ago

hi chris,

I'm trying to refactor the globe project to single page app but im getting error of Module parse failed i think which is related to vertex shader can you help me to resolve this issue

Below is the error im getting

Error

Module parse failed: Unexpected token (1:8) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders > varying vec2 vertexUV; | varying vec3 vertexNormal; |

0
A
A1010 posted 4 years ago

Need help!

I kee getting errors, now I cant even start my server, please help!

0
chris posted 4 years ago

Hi A1010, could you send what error messages you're receiving? They'll be quite helpful with debugging what's going on.

Also, be sure to click on the purple "Video Source Code" button for this video to make sure your files look exactly the same as those listed there. I re-downloaded the course's code and ran it from the spot of this video, and things still function correctly, so there has to be some sort of discrepancy somewhere.

0
A
A1010 posted 4 years ago

After changing my three.js version to yours everything worked fine. How can I convert my nuxt application to a working website?

I know this project can run on localhost, but how can I make it run on a real live server?

0
chris posted 4 years ago

Let me make a quick video on deploying to Netlify. It's a pretty cheap hosting service that makes Nuxt deployments as easy as can be. You can also spin up a free server on there before you transfer your domain name over to it.

Think it would be good to add to this course.

0
chris posted 4 years ago

Just released a new video for this, go ahead and check it out, there I teach how to get the site up and running on a live URL from Netlify. Not the only way to get the site up and running live, but it's definitely a good one in my opinion:

https://chriscourses.com/courses/threejs/videos/deploy-nuxt-with-netlify

0

Providing the lift to launch your development career

© 2026 Chris Courses. All rights reserved.