Parsing error: Unexpected character found at line 238, column 16. Consider using a loader suitable for this file format

Currently, I am attempting to integrate ArcballControls.js controls into my Vue.js application. I've noticed that this particular class contains functions that utilize arrow syntax, whereas every other class in the controls does not. This seems to be the sole distinction I have identified among the various files. Here is the link to the ArcballControls.js file provided by Three.js:

https://github.com/mrdoob/three.js/blob/dev/examples/jsm/controls/ArcballControls.js

Below is the entire jsm/controls directory from Three.js:

https://github.com/mrdoob/three.js/tree/dev/examples/jsm/controls

Upon attempting to utilize these controls within my application, I encountered the following error message:

 error  in ./node_modules/three/examples/jsm/controls/ArcballControls.js

Module parse failed: Unexpected token (238:16)
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
|   //listeners
| 
>   onWindowResize = () => {
| 
|       const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;

@ ./node_modules/cache-loader/dist/cjs.js??ref--13-0!
./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!
./node_modules/cache-loader/dist/cjs.js??ref--1-0!
./node_modules/vue-loader/lib??vue-loader-options!
./src/components/Sidebar/ThreeDCanvas.vue?vue&type=script&lang=js

Here is a snippet from my package.json file:

  "dependencies": {
    "@babel/plugin-transform-arrow-functions": "^7.16.7",
    "three": "^0.133.0",
    "vue": "^2.6.11",
    "vue-style-loader": "^4.1.2",
    "vuetify": "^2.6.3",
    "vuex": "^3.1.2"
  },
  "devDependencies": {
    ...

Within config/index.js, in the module property, this is how I have configured the babel loader. I am uncertain if this is the correct approach:

  module: {
    rules: [
      {
        test: /\.s(c|a)ss$/,
        use: [
          'vue-style-loader',
          'css-loader',
          {
            loader: 'sass-loader',
            // Requires sass-loader@^7.0.0
            options: {
              implementation: require('sass'),
              indentedSyntax: true, // optional
            },
          },
        ],
      },

      {
        test: /\.js$/,
        exclude: /node_modules(?!\/three)/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: [['@babel/preset-env', { targets: 'defaults' }]],
            },
          },
        ],
      },
    ],
  },

Here is the component where I initialize the three-dimensional scene:

<script type="module">
import * as Three from 'three'
import ThreeScene from '@/components/Scene/ThreeScene.js'
import Renderer from '@/components/Scene/Renderer.js'
import Camera from '@/components/Scene/Camera.js'
import HLight from '@/components/Scene/HLight.js'
import DLight from '@/components/Scene/DLight.js'

//import is here
import { ArcballControls } from 'three/examples/jsm/controls/ArcballControls.js'

import ObjectLoader from '@/components/Scene/ObjectLoader.js'
import CubeLoader from '@/components/Scene/CubeLoader.js'

export default {
  name: 'ThreeDCanvas',
  data() {
    return {}
  },
  methods: {
    init() {
      this.scene = new ThreeScene()
      this.camera = new Camera()
      this.renderer = new Renderer({ antialias: true })
      this.objectLoader = new ObjectLoader()
      this.controls = new ArcballControls(
        this.camera,
        this.renderer.domElement,
        this.scene
      )

I would greatly appreciate any assistance in identifying what may be incorrect in my approach. Thank you!

Answer №1

Implemented babel loader in the config/index.js file of the module.

{
    test: /\.jsx?$/,
    exclude: /node_modules/,
    use: ['babel-loader']
},

Optimized the package.json by removing unnecessary dependencies and downgrading some. Running on Node version 14.17.4, which led to downgrading node-sass to 4.14.1. Fixed the issue with the loader for threejs, but encountered problems with sass loader.

"node-sass": "^4.14.1",
"prettier-eslint": "^13.0.0",
"sass": "^1.49.7",
"sass-loader": "^7.3.1",
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",

Removed babel-loader and babel-preset-es2015 from package.json.

My babel-config.js looks like this:

module.exports = {
  presets: ['@vue/cli-plugin-babel/preset'],
}

After making these changes, I successfully accessed the arcballcontrol from threejs.

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

Certain mobile devices experiencing issues with AngularJS filters

Currently, I am attempting to filter an AngularJS array by utilizing custom filters within a controller. The filters are functioning correctly on certain mobile devices, yet they are not working on others. Here is the code snippet that I am using: var a ...

Splitting JavaScript files in the "dist" folder based on their source folders can be achieved in Angular by using G

I’m currently utilizing gulp-angular for my project, but I’m facing a challenge due to my limited experience with node and gulp when it comes to modifying the default scripts task. My goal is to generate an optimized JS file for each folder within my ...

Setting up global Axios configuration with authentication in NuxtJS using VueJS

In my quest to configure Axios globally with authentication in NuxtJS - VueJS (primarily NUXTJS), I am facing a challenge. What I aim for is pretty straightforward: If a user is logged in and has a token in $store, I want Axios to use this token. If the u ...

What is the preferred approach in JavaScript: having a single large file or multiple smaller files?

Having a multitude of JavaScript files loaded on a single page can result in decreased performance. My inquiry is this: Is it preferable to have individual files or combine them into one JavaScript file? If consolidating all scripts into one file is the ...

Attach a child element to the bottom of its parent div when the parent div reaches the bottom

I'm looking to make a child div stick to the bottom when the parent div reaches the bottom of the browser window. Note: This behavior should only occur when the parent div is pushed down, not when the page is scrolled down. For instance, in my demon ...

How One Simple Click Can Impact Every Button in jQuery Ajax操作

Whenever I try to click a button that should only affect a specific id, it ends up affecting every button on the page by sending data to our API as well. You can check out a snapshot of my page here. Each row has a unique id, but when I click the vote butt ...

What is the process for transferring a file uploaded from a Vue front end to a Laravel controller?

I'm facing an issue with passing file data from a Vue file upload form to a Laravel controller. Although the data is successfully passed from the page to the store in Vue, I'm unable to access it in my controller: Vue page: update() { this.$st ...

Tips for adjusting image size to take up only half of the screen in NextJS

Struggling to resize an image to fit only 50% of the screen in NextJS? The Image component provided by NextJS comes with its own inline styling, making it tricky to customize. Currently, I attempt to style the image by wrapping the Image component in a spa ...

if the current value in the field surpasses the specified value in JavaScript

Looking to incorporate an additional condition into a JavaScript function initial condition if (content.length==elmnt.maxLength) new condition if (content.length==elmnt.maxLength && current form field value > 1400) How can I properly implement the ...

How to use RegExp to locate the final return statement within a JavaScript code string

Take a look at this code snippet: cont x = 10; function foo() { return x; // ;; end of function ;; // /* here is a some text here too */ } function bar() { return 10 } return foo() + bar(); // ;;done;; // /* yolo yolo */ This string cont ...

What is preventing the table from extending to the full 100% width?

Displayed above is an image showing an accordion on the left side and content within a table on the right side. I have a concern regarding the width of the content part (right side) as to why the table is not occupying 100% width while the heading at the ...

Achieving consistent text alignment in HTML and CSS without relying on tables

As I delve into the world of HTML and CSS, I've taken a traditional approach by crafting a login page complete with three input controls (two text inputs and one button). To ensure proper alignment of these elements, I initially turned to the trusty & ...

The most effective method for incorporating a header and footer into an HTML page utilizing a variety of client-side frameworks

Looking for a solution for my HTML project where I want to incorporate a header and footer to minimize rework. Any suggestions on a good approach? I have experimented with AngularJS using ng-include, and here is the code snippet: var app = angular.module ...

Did the menu get shifted downwards on the mobile version by using bootstrap?

Here is the desktop version of a navigation bar. https://i.sstatic.net/e595L.png This image shows the mobile version after clicking on the hamburger button. https://i.sstatic.net/ng1tK.png I would like the menu to open when I click on the hamburger, bu ...

Encountering Error when Attempting to Load Webpack Dependencies for Browser

I'm currently in the process of manually scaffolding an Angular 6 app (not using the CLI). Everything was going smoothly until I encountered a webpack error: ERROR in window is not defined After researching online, it seems like I may be missing som ...

Check through an array for any updates whenever a function is called and my react state is altered

I am currently working on a project related to playlists. My goal is to display the image attached to each song whenever that song is clicked from the playlist. Here is the code I have so far... const Component = () => { const value = useContext(DataC ...

When faced with the scenario of having the hashtag in the href attribute and a browser's back button, it

Hello everyone, I've encountered an issue with the "back" action in my browser. When I click on a link, it takes me to a specific page due to a JavaScript function being called. However, when I hit the back button, it simply removes the "#" from the U ...

Failure to display updated property value

After rendering an array of objects, I am attempting to add a new property using a function. However, the new property value is not displaying on the page even though it is present when I log the object in the console. The new property that I want to add ...

Exploring Rxjs through fundamental queries

Currently, I am working on a small application using Angular 2 and have installed Rxjs 5. However, I have encountered various ways of importing the Rxjs library in tutorials. The code mentioned in the Angular 2 documentation is not functioning properly i ...

Can you spot the real transformation happening?

Is there a built-in way (possibly in one of the frameworks) to determine if a form has been modified from its initial values? The onchange event is not sufficient, as it triggers even if no real change has occurred (such as toggling a checkbox on and off ...