Facing an issue with the React-Three-Fiber Canvas component triggering a 'Module parse failed: setter should have exactly one param' error in my Next.js application. Any suggestions for resolving this issue

Having issues with the Canvas component in react-three-fiber not functioning correctly in my next app.

I am new to react-three-fiber and Next.js, and when I try to use the Canvas component, I encounter the following error:

./node_modules/three/build/three.module.js
Module parse failed: setter should have exactly one param (1433:13)
|         return this.source.data;
|     }
>     set image() {
|         let value = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
|         this.source.data = value;

Here is my page.tsx file:

"use client";

import { Canvas } from "@react-three/fiber";
import Box from "@/components/Box";

export default function Home() {
  return (
    <Canvas>
      <pointLight position={[10, 10, 10]} />
      <Box />
    </Canvas>
  );
}

The content of Box.tsx:

import { useRef, useState } from "react";
import { useFrame, ThreeElements } from "@react-three/fiber";

export default function Box() {
  const ref = useRef<ThreeElements["mesh"]>(null!);
  const [hovered, hover] = useState(false);
  const [clicked, click] = useState(false);
  useFrame((state, delta) => (ref.current.rotation.x += delta));
  return (
    <mesh
      ref={ref}
      scale={clicked ? 1.5 : 1}
      onClick={(event) => click(!clicked)}
      onPointerOver={(event) => hover(true)}
      onPointerOut={(event) => hover(false)}
    >
      <boxGeometry args={[1, 1, 1]} />
      <meshStandardMaterial color={hovered ? "hotpink" : "orange"} />
    </mesh>
  );
}

This is how my next.config.js looks like:

/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ["three"],
};

module.exports = nextConfig;

Answer №1

Recently encountering an issue linked to NextJS's transpiler while working on [email protected]. After updating to the most recent version, [email protected], the problem was swiftly resolved.

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

Is there a way to customize the timepicker pop-up so that it extends the entire width of the parent form control

<FormControl fullWidth> <LocalizationProvider dateAdapter={AdapterDayjs}> <TimePicker views={["hours", "minutes", "seconds"]} label={t("StrategyManager.Select_Time")} value={timer} ...

Leveraging Next.js to interact with secondary backend services while passing a JWT token through server actions

I'm currently facing an issue where I am working with Nextjs and NextAuth, and I need to access another backend by setting the Bearer token in the Authorization header. My concern is not exposing the token to the client, so I aim to retrieve it in a s ...

In MUI v5, the Autocomplete default value is not set

When I try to use the defaultValue prop in the Autocomplete component of MUI v5, the value always ends up being undefined. This is a snippet from my code: const vehicles = [ { name: "Toyota", model: "Camry" }, { name: "Ford&qu ...

I'm sorry, but your request to access the API from the React localhost has been hinder

Currently, I am delving into the world of React, a JavaScript framework. My task involves fetching a token from an API provided by this service: . To achieve this, I must include my X_CONSUMER_KEY in the request. Here is the approach I am taking using the ...

Notification within the conditional statement in React JS

I am working on validating phone number input within a React JS component using an if/else statement. If the user enters letters instead of numbers, I want to display a message saying "please check phone number". While I have been able to create a function ...

Utilizing React Native for Seamless Navigation: Understanding Stack and Tab Navigation (Ensuring the route component is a React component)

Attempting to create a StackNavigator that can navigate into a TabNavigator, but encountering an error stating: "The component for route must be a React component." The TabNav is not a physical file folder; it is intended to be called once the user logs i ...

Styling multiple Higher Order Components (HoCs) using Material UI withStyles

When developing my application, I encountered an issue with using Higher Order Components (HoCs) and withStyles for styling. If I apply multiple HoCs to one component, the classes prop of the first HoC gets passed to the next one in the compose chain, caus ...

Separating screens for logged in and logged out users in React Router with Firebase is not possible

I'm currently developing an application using React and Firebase. The app has a requirement for user authentication to access their own timeline. To achieve this, I have decided to split the app into LoggedIn screens and LoggedOut screens. In the App ...

Is it possible to nest a table inside another table using material-UI's Grid component?

I'm currently working on creating a React 16.13.0 application and trying to incorporate the material-ui Grid component. I'm facing issues with nesting a Grid within another Grid. My objective is to nest this table: <Grid container item spaci ...

Tips for managing blur events to execute personalized logic within Formik

I am currently delving into the world of React/Next.js, Formik, and Yup. My goal is to make an API call to the database upon blurring out of an input field. This call will fetch some data, perform database-level validation, and populate the next input fiel ...

Jest in combination with Next/Dynamic is causing an error that is not supported

While working on testing for my component, I encountered an error involving the use of: ... const Rating = dynamic(import('components/Rating')); ... In addition, I am utilizing jest-next-dynamic: beforeAll(async () => { await preloadAll() ...

What could be the reason for React not memoizing this callback?

I am encountering an issue with my Next.js project where the _app.tsx file contains the following code: const Root = ({ Component, pageProps }) => { ... const handleHistoryChange = useCallback((url) => { console.log({ url }); }, []); u ...

Enhance the language with react-intl and MobX State Tree integration

Currently, I am integrating react-intl with Mobx state tree for the first time. Within my project, there are two buttons located in the header section - one for 'it' and the other for 'en'. Upon clicking these buttons, the selected lan ...

Unspecified parameter for Next.js dynamic route

Currently, I am developing an e-commerce application using next.js with Typescript and MongoDB. To better understand my project, let's take a look at my existing file structure: https://i.stack.imgur.com/tZqVm.png The mainPage.tsx file is responsibl ...

Is it time to swap out "localhost" with the service name in Docker?

I have successfully dockerized my reactjs app and express app. Check out the docker-compose.yml file I used: version: "3" services: client: image: react-app build: ./client ports: - "3000:3000" volumes: ...

Utilize the "incorporate" feature to include any string within an array

I am currently working on improving the search function in my application. This particular search function takes input from a search bar and is designed to handle multiple search terms. For example, it should be able to handle queries like "javascript reac ...

Is it crucial to commit to memory a Tiny/Affordable Component? - ReactJS

Imagine having a child component that simply returns a div element Child Component : function Child() { return <div className={styles.alertBox}>No Data Found</div>; } Every time the parent state changes, this child component will re-render. ...

Tips for ensuring only one property is present in a Typescript interface

Consider the React component interface below: export interface MyInterface { name: string; isEasy?: boolean; isMedium?: boolean; isHard?: boolean; } This component must accept only one property from isEasy, isMedium, or isHard For example: <M ...

I'm having trouble with getting npm start to function properly. I've exhausted all my options and I'm feeling lost

Every time I execute npm start in my React project, an error pops up: [email protected] start C:\Users\AyaLe\Desktop\React\myapp react-scripts start It seems there might be a problem with the project's dependency tre ...

Does Next.js pre-render every page, or does it only pre-render the initial page?

As I dive into the world of nextjs, I'm coming across conflicting information. Some sources claim that nextjs only prerenders the first page, while others suggest that all pages are prerendered by default. This contradiction has left me confused about ...