Using curly braces for imports within a Nuxt component

I am facing an issue with importing Three.js in a Nuxt component.

<script>
import * as THREE from "three";
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
..

Although the first line of code works fine, the second one is throwing an "Unexpected token {" - syntax error, and so is

const { OrbitControls } = require('three/examples/jsm/controls/OrbitControls')

The import syntax used in the first version follows the Three.js documentation guidelines.

Answer №1

After encountering a dilemma, I found a solution by referencing an answer I previously provided in a different discussion: link

Recently, I stumbled upon a fascinating project and was intrigued by its functionality. In essence, it operates as a Single Page Application (SPA). Implementing this approach in my own project yielded successful results.

In the nuxt.config.js

export default {
  mode: "spa",
  ..

Evidently, the issue at hand pertains to server-side rendering.

------ Insights on Universal Mode ------

In striving for universal integration within my application, I experimented with conditionally importing plugins. It's important to note that the following method is ineffective. Nonetheless, I present it as another avenue of exploration for situations where SPA implementation may not be feasible.

Transfer

import Vue from 'vue'
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"
Vue.use(OrbitControls)

to a file named threeimports.js within the plugins directory and append

  plugins: [
   { src :"~/plugins/threeimports.js", ssr: false},
  ..

to the nuxt.config.js

Initially, I assumed that OrbitControls would be globally accessible throughout the project, but that wasn't the case. The root cause lies in the curly bracket syntax, which differs from how other modules are integrated successfully without utilizing brackets.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Avoiding repeated execution of event handlers in subviews of Backbone

Working with Backbone, I have a list container view that should house multiple section views with event handling. However, the issue is that the event is triggered as many times as there are subviews inside the container. I understand that moving the clos ...

Associating fixed UI element interactions with Backbone's View component

I'm looking to add a click event to a button without relying on using a template. Creating the HTML <div id="transfer"> <input type="text" placeholder="From Address" id="fromAddress" /> <input type="text" pla ...

Simulate a keyboard key being pressed and held for 5 seconds upon loading the page

Is it possible to create a script that automatically triggers an event to press and hold down the Space key for 5 seconds upon page load, without any user interaction? After the 5 seconds, the key should be released. It is important to emphasize that abso ...

When working in Javascript, make sure to replace newline and carriage return characters in strings with empty spaces. Also, don't forget to replace the literal sequences and

When working with Javascript, I am looking to perform multiple string replacements as outlined below. Remove all newlines and carriage returns Swap out instances of \n with a newline character Change occurrences of \r with a carriage return char ...

Is it possible to generate an axonometric oblique, cavalier, or cabinet using threejs?

I stumbled upon some tutorials for setting up an isometric camera in Three.js here, but I'm curious about how to create an axonometric oblique. Any insights? ...

creating intricate nested routes within the same Vue component by using a conditional switch case

I am currently developing a players module. Within this module, there are 3 routing cards on the initial page. Each card leads to the next page, which contains multiple routing cards related to their parent card. For Example: 1. 1st level Card(Player N ...

Is it possible to refresh an iframe with PHP once a certain condition is satisfied?

I have a situation with two pages - one is my PHP script and the other is an HTML page containing two iframes. > <html> > > <iframe name=1></iframe> <iframe name=2></iframe> > > </html> Currently, ifram ...

How to Preserve Scroll Position when Toggling a Div using jQuery

I've been struggling to find a solution for maintaining the scroll position of my page after a JQUERY toggle event. I've searched extensively but haven't found a fix yet. <script src="Scripts/_hideShowDiv/jquery-1.3.2.min.js" type="text/ ...

Sort with AngularJS: orderBy multiple fields, with just one in reverse

Currently, I am faced with the challenge of filtering data based on two variables: score and name (score first, followed by name). This task involves various games, some of which have scores in reverse order (like golf) while others maintain a normal scor ...

Leverage JSON files for pagination in NextJS

I am currently developing a science website where the post URLs are stored in a static JSON file. ScienceTopics.json- [ { "Subject": "Mathematics", "chapters": "mathematics", "contentList": [ ...

Reveal a segment of a picture

Is there a way to display only a section of an image using either jQuery or another JavaScript method? For example: image: [ ] [ -------- ] [ - - ] [ - part - ] [ - - ] [ -------- ] [ ...

Choose the element before and add a style effect with CSS

I'm trying to create a layout with 3 <div> elements in one horizontal line, each with a width of 33.33%. When hovering over one div, I want its width to expand to 50% while the other two shrink to 25%. <div id="A"></div> <div id= ...

Retrieve information from an external JSON API using jQuery

I need help with reading JSON data using jQuery. I have tried the code below but it doesn't seem to be working. This is the link to my JSON file: and here is my code snippet: $.getJSON("http://goo.gl/PCy2th", function(data){ $.each(data.PlayList ...

The vertical tabs in JQueryUI lost their functionality when a few seemingly unrelated CSS styles were added

Check out the JsFiddle demo here I embarked on a mission to craft JQueryUI Vertical tabs by following the guidance provided in this example. The source code within the aforementioned link contains specific CSS styles: .ui-tabs-vertical { width: 55em; } ...

Sending JSON objects as parameters to WebMethod

I've encountered various errors while passing parameters to my WebMethod. Below are my attempts and the corresponding errors: globalData is an array, mapping is an array that can be deserialized to List<Mapping>, selectedFund is an integer. C ...

Encountering a VueJS error with Google Cloud Logging Winston: "TypeError: The 'original' argument must be a Function."

I have been attempting to integrate @google-cloud/logging-winston into my VueJS project by closely following the guidelines provided in both the npm package and Google Cloud docs. However, I am encountering an error message stating "TypeError: The &q ...

Competition among fetch requests

I am currently developing a tracker that is designed to gather data from our clients' websites and send it to our API using fetch requests when site users navigate away from the page. Initially, I planned to utilize the beforeunload event handler to ...

Applying the document height to window height ratio to create a scale ranging from 1 to 100

My goal is to create a scroll bar using two divs with heights of 110px and 10px. The smaller one will be nested inside the taller one, allowing for adjustment of its margin-height from 0 to 100px while still fitting within the larger div. When I refer to ...

Ways to utilize JavaScript to identify if a flash is launching in a separate tab

On my website, I have embedded a third-party flash player using an iframe. Whenever a user clicks on a specific area within the flash player, a new tab is opened in the browser. I am trying to track the frequency of this occurrence. However, I have encoun ...

Creating a dynamic two-player chess application using Django - requiring the player's chess board to automatically update whenever the opponent makes a move

I am looking for a solution where each player has their own webpage equipped with a Javascript chessboard GUI interface that allows them to click and drag pieces. The challenge is ensuring that when one player makes a move, the other player's chessboa ...