Error encountered with Three.js SceneExporter due to Uncaught Syntax issue

Recently, I've been attempting to export a three.js scene using the SceneExporter tool. Here is the code snippet I have been working with:

var output = new THREE.SceneExporter().parse(scope.renderingEngine.scene);

Unfortunately, this has resulted in an error message popping up during execution:

Uncaught SyntaxError: Unexpected token u

The error seems to originate from line 750 of SceneExporter.js, specifically where the JSON data is being parsed by

new THREE.SceneExporter().parse(scope.renderingEngine.scene);

I have kept my scene fairly simple without any complex elements and even tested it without textures, yet the error persists.

Upon further investigation, I tried modifying the problematic line to just return output. However, when I attempt to stringify and save the output as a JSON file, the generated JSON does not validate and throws the following error:

Parse error on line 1:
"{    \n\t\"metadat
^
Expecting '{', '['

Here are lines 1-10 of the JSON file:

"{
    \n\t\"metadata\": {
        \n\t\t\"formatVersion\": 3.2,
        \n\t\t\"type\"\t\t: \"scene\",
        \n\t\t\"generatedBy\"\t: \"SceneExporter\",
        \n\t\t\"objects\": 153,
        \n\t\t\"geometries\": 144,
        \n\t\t\"materials\": 5,
        \n\t\t\"textures\": 1\n\t
    },
    \n\n\t\"urlBaseType\": \"relativeToScene\",

Has anyone else encountered a similar issue while working with three.js?

Answer №1

An unexpected syntax error occurs when an "ILLEGAL" token is encountered, usually due to the misuse of escape sequences such as "\n\t\t" outside of strings. It is unclear why these escape sequences are being used outside of their intended context, and it is questionable whether special characters should even be included in JSON data.

Furthermore, I have noticed instances where "\" is included within strings. It is important to note that a single "\" is not a valid escape sequence and will result in the "Unexpected token: ILLEGAL" error. Instead, "\", which represents a literal "\" character, should be used for proper syntax formatting.

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

Angular2 - Access to fetch at 'https://example.com' from

Requesting some guidance on integrating the forecast API into my angular2 application. Currently facing a Cross-Origin Error while attempting to access the API. Any suggestions on resolving this issue? search(latitude: any, longitude: any){ consol ...

The issue of Datatables child row not refreshing when using AJAX

I'm attempting to retrieve child row data in Datatables using AJAX: $('#myTable tbody').on('click', 'td', function () { var tr = $(this).closest('tr'); var row = myTable.row( tr ); if ( row.child.isS ...

Cannot access jquery within an angular directive

I've been attempting to incorporate jquery-ui's sortable feature on the elements within an ng-repeat loop. The issue I'm facing is that I am unable to actually perform the sortable action on these ng-repeat elements. I have searched for so ...

Transform C# ASPX to handlebars format

Initially, my task was to choose and relocate a single li from many options into a different div. But now, I am required to achieve the same result using a JS template which utilizes handlebars. The C# section is as follows: <li class="l-row__item pr ...

What steps can I take to make my search button work with this JavaScript code?

I am struggling with integrating my custom search bar with a JavaScript code to make it functional. Here is the code snippet for the Search Button: document.getElementById('searchform').onsubmit = function() { window.location = 'http:/ ...

What is the best way to specify a function parameter as a Function type in TypeScript?

I'm currently delving into the world of TypeScript and I am unsure about how to specify a function parameter as a function type. For instance, in this piece of code, I am passing a setState function through props to a child component. const SelectCity ...

Execute a simulated click on the Material-UI Tabbar using a programmatic approach or keyboard shortcut

In my electron/react application, I am implementing Material UI tabs in the following manner: <Tabs> <Tab label="View1" > <View1 /> </Tab> <Tab label="View2"> ...

Unleashing the power of async/await in React: A comprehensive guide

Looking to simplify my code, I am interested in implementing async and await for the following code snippet. However, I am unsure of how to proceed. Any examples would be greatly appreciated. deletePost = (post) => { var post_id = post; try { ...

Listening for a client's socket emit through Express Routes

I have successfully implemented the functionality to emit and receive messages using socket.io between the server and client with the code in server.js. const express = require('express') const app = express() const port = 4000 var http = require ...

A code to ensure input values are always set to the maximum possible value

I recently developed a script that monitors the live value property of 3 <input> elements, correcting them if the live value is outside the specified range. However, I encountered an issue where the script automatically sets the value to the max as s ...

Using Vue3 and Vuex4: How to efficiently render only a subset of items from an array with v-for

Hello, I'm a first-time user and beginner developer seeking some assistance. I am in the process of creating a basic web application that retrieves an HTTP JSON response from an API and displays a more visually appealing list of results. However, I&ap ...

What is the process for extracting HTML content using the JavaScript executor?

import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; public class WebDriverExample { public static void main(String[] args) { System.setProperty("webdriver.c ...

The error callback in Jquery ajax is triggered despite receiving a 200 status code in the response

I am facing an issue with my ajax code. The success callback contains an alert that is not working properly. Here is the code snippet: $(".change_forex_transaction_status").click(function(){ $("#insufficient_funds").css("display","none"); var id = $( ...

In the useEffect hook, the context userdata initializes as an empty object

I am facing an issue with my code where the imported object is not being read by useEffect. The user object is imported from another context and when I try to use it in the useEffect of DataContext, it returns an empty object. I suspect that useEffect is b ...

Querying specific data from the API using unique identifiers

If the api.football-data.org/v1/competitions holds this data: { "_links": { "teams": { "href": "http://api.football-data.org/v1/competitions/444/teams" } }, "id": 444, "caption": "Campeonato Brasileiro da Série A", ...

Error encountered with Vuetify stepper simple component wrapper and v-on="$listeners" attribute

I'm working on developing a custom wrapper for the Vuetify Stepper component with the intention of applying some personalized CSS styles to it. My aim is to transmit all the $attrs, $listeners, and $slots. I do not wish to alter any functionality or ...

What steps should I take to display a Modal upon a successful Oauth2 redirect?

I am currently working on an older web application that utilizes the portal/portlet architecture. Within the application, I have a feature that loads in a modal when accessed. The modal includes navigation functionality that allows customers to navigate t ...

Utilize Javascript to input text into a webform

I am working on creating a bot that simulates user input for the WattsApp web website. When I manually type a message into the website, it enables a button that allows me to send the message. However, when my script runs, it finds the input box, changes t ...

The timepicker is set to increment by 30-minute intervals, however, I would like the last time option to be 11:

I am currently using a timepicker plugin and am trying to set the last available time option to be 11:59pm. Despite setting the maxTime attribute in my code, the output does not reflect this change. Any suggestions on how to achieve this would be highly ap ...

Retrieve the output from PHP in JSON format and then utilize jQuery to parse it

I am currently working on a jQuery function $.post(file.php), where the data is being sent to "file.php" and returned in JSON format using json_encode(). Although I am able to successfully retrieve the result, I am unsure how to separate the individual i ...