Next.js focuses solely on rendering markup and does not run any custom code

I am in the process of creating a website, where currently the only functionality available is to change themes by selecting an option from a dropdown menu (the theme is an attribute that uses CSS variables).

Everything was functioning properly, however today, for some unknown reason, all TypeScript code stopped executing. No matter what I try, there are no console logs being displayed and no attributes are being set.

Here is the code:

'use client';
import { createContext, useEffect, useState } from 'react';
import { Themes, setCssTheme } from './misc/themes';
import { Form } from 'react-bootstrap';

const ThemeContext = createContext(Themes.PrincessPink);
const themeOptions = Object.values(Themes).map((theme) => (
    <option value={theme} key={theme}>
        {theme}
    </option>
));
export default function Home() {
    const [theme, setTheme] = useState(Themes.PrincessPink);
    useEffect(() => {
        setCssTheme(theme);
    });
    return (
        <main className="flex min-h-screen flex-col items-start justify-normal">
            <ThemeContext.Provider value={theme}>
                <Form.Select
                    className="m-4"
                    onChange={(e) => {
                        //TO DO: If the source code of the page is modified and incorrect value will be passed into here, will it break? How to handle this?
                        setTheme(e.target.value as Themes);
                        setCssTheme(theme);
                    }}
                >
                    {themeOptions}
                </Form.Select>
            </ThemeContext.Provider>

            <div className="ml-4"> selected theme: {theme} </div>
        </main>
    );
}

Code for themes:

export enum Themes {
    PrincessPink = 'PrincessPink',
    OrangeDanger = 'OrangeDanger',
    NextJsExample = 'NextJsExample',
}
export function setCssTheme(theme: Themes) {
    document.documentElement.setAttribute('data-theme', theme);
    console.log('theme set to: ' + document.documentElement.getAttribute('data-theme'));
}

Dependencies (which might be relevant):

...

On my end, the result is nothing - events are not triggered, code is not executed, only HTML markup and elements from React Bootstrap are visible on the webpage.

This is how it appears on my screen:

https://i.sstatic.net/Q6ftA.png

Answer №1

It's a mystery to me why, I can't pinpoint the exact cause, but for some unknown reason the solution ended up being a full reinstallation of node, next.js, and all related components. Including clearing out directories like Appdata, temp, cache, etc.

I followed this guide: How to completely remove node.js from Windows

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

incomplete constructor for a generic class

I have multiple classes that I would like to initialize using the following syntax: class A { b: number = 1 constructor(initializer?: Partial<A>) { Object.assign(this, initializer) } } new A({b: 2}) It seems to me that this ini ...

The practice of following the UpperCamelCase convention post object transformation

I encountered a situation where I have an object that returned the result from an RxJs subscribe method: result: any { message: null role: Object success: true } To better manage this object in TypeScript, I decided to convert it to a type ca ...

React does not allow objects as a valid child element. This error occurs when an object with keys {nodeType, data, content} is found

I am encountering an issue with displaying content from Contentful on the server component. Everything is functioning correctly with no runtime errors, but I am receiving this specific error message: "Objects are not valid as a React child (found: object w ...

Component in NextJS

Is there a way to automatically refresh a remote JSON every 30 seconds in NextJS? I had it working smoothly in ReactJS, but after migrating to NextJS, errors started popping up. The issue seems to be related to certain elements that work fine in my ReactJ ...

Is it necessary to declare parameters for the super class constructor in Typescript React? If so, what would those parameters be?

I'm struggling to understand the specifics of the constructor in this code. Can anyone clarify what arguments the constructor for super() and constructor() should have? import * as React from "react"; import styles from "./ScriptEditor.module.scss"; ...

Retrieving Information from an Angular 2 Component

Struggling to figure this out, I am attempting to dynamically add user video data that includes a video URL. My goal is to access the data from the component so I can use it in my HTML. I've attempted the following approach. app.component.ts import ...

Guide on updating the URL for the login page in the Next-Auth configuration

I successfully integrated authentication using Next-Auth in my Next.js project. In the index.js file (as per the Next-Auth documentation), I only return a User if there is an active session export default function Home({characters}) { const {data: ses ...

Filtering data in Angular from an HTML source

Looking to filter a simple list I have. For example: <div *ngFor="let x of data"></div> Example data: data = [ { "img" : "assets/img/photos/05.jpg", "title" : "Denim Jeans", "overview": "today" ...

Building a React Native authentication system using Next.js and NextAuth

I currently have a website that has authentication functionality implemented using Next.js, NextAuth, Prisma, and MySQL. My next step is to develop a React Native app for this website, but I'm uncertain about how to handle authentication. Should I ut ...

Error: The current call does not match any existing overloads - TypeScript, NextJS, styled-components

I'm facing an issue while trying to display icons in the footer of my website. The error message "Type error: No overload matches this call" keeps appearing next to my StyledIconsWrapper component, causing Vercel deployment to fail. Despite this error ...

Are You Able to Develop a Floating Window That Stays Persistent in JavaScript?

Looking to create a persistent floating window in a NextJS 14 app. This window needs to remain on top, even when navigating between browser windows. Want it to stay visible even when the browser window is minimized, like a Picture-In-Picture feature. Mos ...

Exploring Angular data iteration with Tab and its contentLearn how to loop through Tab elements

Upon receiving a response from the API, this is what I get: const myObj = [ { 'tabName': 'Tab1', 'otherDetails': [ { 'formType': 'Continuous' }, { 'formType& ...

Angular2 - the pipe was not located while organizing records

I've successfully fetched data from an API and displayed it in the view, but I'm struggling to organize the data by date. Whenever I attempt to do so, I encounter this error message: The pipe 'groupBy' could not be found pipe.ts impor ...

Encountering 'null' error in template with Angular 4.1.0 and strictNullChecks mode

After updating Angular to version 4.1.0 and activating "strictNullChecks" in my project, I am encountering numerous errors in the templates (.html) that look like this: An object may be 'null' All these errors are pointing to .html templat ...

Angular examine phrases barring the inclusion of statuses within parentheses

I require some assistance. Essentially, there is a master list (arrList) and a selected list (selectedArr). I am comparing the 'id' and 'name' from the master list to those in the selected list, and then checking if they match to determ ...

What is the best way to implement useRouter in Next.js version 14?

When I utilize router = useRouter() and then try to redirect with router.push('auth/new-password') from the path 'auth/login/approve', I unexpectedly end up being routed to 'auth/login/auth/new-password'. Can someone explain t ...

The issue with NextJs Firebase Hosting not reading environment variables when built on GitHub Actions

I am currently in the process of deploying my NextJs application on Firebase hosting using Github Actions. Below is the workflow file I have set up for this deployment: name: Deploy to Firebase Hosting on merge on: push: branches: - main jobs: ...

Unexpected behavior in Typescript validation of function return object type

After some investigation, I came to the realization that TypeScript does not validate my return types as anticipated when using the const myFn: () => MyObjType syntax. I ran some tests on the TypeScript playground and examined the code: type MyObj = { ...

Having trouble setting the state of an array using NextJS useState?

I'm facing an issue where the array saved to a useState state is not updating properly. Despite properly returning values for the variable first, the variable "data" remains an empty array. Interestingly, adding a console.log("restart") statement und ...

Interface with several generic types

In an attempt to create a parser that can parse data fields and convert them into a complete form for display purposes, the fields property plays a crucial role. This property will define each field in a JSON data array that the client receives from the ur ...