Issue: Module 'serialize-javascript' not found despite being present in the 'node_modules' directory after executing npm start command in ReactJS project

My npm start suddenly stopped working. This issue arose after I switched to an unused branch with unrelated histories, made some changes, pushed them (unaware that the branch was outdated), then used git checkout -f "" to go back to the recent branch. Now, I am unable to run it on any of my branches due to the error

Error: Cannot find module 'serialize-javascript'

Here is the full error message:

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'serialize-javascript'
Require stack:
- /home/abdullah/ecommerce-recommend-frontend/node_modules/rollup-plugin-terser/index.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-build/build/lib/bundle.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-webpack-plugin/build/generate-sw.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-webpack-plugin/build/index.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/react-scripts/config/webpack.config.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/react-scripts/scripts/start.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
…

The folder

node_modules/serialize_javascript
does exist and contains a settings.json file:


{
  "spellright.language": [
    "en"
  ],
  …
}

I attempted running npm install globally as well as inside the serialize_javascript directory but encountered issues:

up to date,
1 critical severity vulnerability
Some issues need review.

Run `npm audit` for details.

After running npm audit:

# npm audit report

node-serialize  *
Severity: critical
Code Execution through IIFE - https://npmjs.com/advisories/311
No fix available

1 critical severity vulnerability
Some issues need review.

An attempt to check node -v also led to a MODULE_NOT_FOUND error:

internal/modules/cjs/loader.js:883
…

Error: Cannot find module '/home/abdullah/ecommerce-recommend-frontend/–v'
…

Note: This problem started after I uninstalled node and reinstalled it in WSL using sudo:

rm -rf /usr/local/lib/node_modules/npm 
sudo apt-get remove npm
sudo apt install nodejs
sudo apt-get update

Any suggestions? I'm considering removing Node from Windows and performing a fresh installation.

Answer №1

Disregard that, I ended up using an older serialize_javascript module from a previous commit because it contained additional components besides the settings.json file. Afterward, I executed npm install to ensure it functioned correctly.

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

How can I dynamically populate my select field with JSON data using React.js?

My goal is to fetch data from an API and use the 'symbol' JSON field as options for a select dropdown. However, I'm encountering an issue: 'TypeError: Cannot read property 'length' of undefined.' Beneath my code, I' ...

Does a React functional component continuously re-render if it contains a child component?

For the past few days, I've been facing a performance issue in a React app (specifically React Native). The core of the problem is this: Whenever a function component Parent has another function component as its Child, the Parent will consistently re ...

Dealing with Regular Expressions in Javascript and PHP Challenge

I am struggling to achieve the same outcome with my JavaScript as I do with my PHP code. The issue lies in how JavaScript omits backslashes, unlike PHP. To address this, I have included random forward and backward slashes to cater for different systems. Se ...

Detecting a targeted POST event in JavaScript without any libraries

In a situation I'm facing, an AngularJS website is not loading jQuery (except for jQLite). My goal is to monitor events with particular parameters. Unfortunately, I'm unable to make any changes to the source code. However, by examining the event ...

Instructions on utilizing sockets for transmitting data from javascript to python

How can I establish communication between my Node.js code and Python using sockets? In a nutshell, here is what I am looking for: Node.js: sendInformation(information) Python: receiveInformation() sendNewInformation() Node.js: receiveNewInformation( ...

Enforcing Sequential Execution in Node.js

I have finally grasped the concept of callbacks in node.js, but now I am striving to ensure that my code executes in the correct sequence. Here are the steps I aim to follow: Retrieve the URL content using cheerio. Iterate through each <td> elemen ...

Increasing the concealment of items

My query is about creating an expandable tree structure while iterating through an array in AngularJS. I managed to make it work, but the issue is that all nodes expand and collapse together. Here's my HTML: [...] <div ng-repeat="item in items"&g ...

Efficiently transferring time values from dynamically created list items to an input box using JavaScript

Is there a way to store a dynamically generated time value from an li element into an input box using JavaScript? I have a basic timer functionality on my website that includes starting, stopping, pausing, taking time snaps, and resetting them. These time ...

Handling typeError in Vue.js JavaScript filter for object manipulation

I need to sort an object based on state names (e.g. Berlin, Bayern ...). Below is the API response I received. "states":{ "Bayern":{ "total":13124737, "rs":"09", "va ...

Receiving and transmitting messages repeatedly in Discord.JS

Currently, I am developing a simple bot. Interestingly, the bot seems to be responding multiple times to a single command. Here is the code snippet: const Discord = require('discord.js'); var bot = new Discord.Client(); const PREFIX = "+"; var ...

The specified data type is Schema.Types.ObjectId, and it triggers an error stating "ReferenceError: Schema is not

As I was creating a database schema and trying to reference the userschema, I encountered an issue while writing the following code: postedBy: { type: Schema.Types.ObjectId, ref: 'User' }, type: Schema.Types.ObjectId, ^ ReferenceE ...

Being unable to modify a variable beyond its specified function boundaries

Despite the user.length being greater than zero, the duplicate variable is always false. The console first prints 'false' and then shows the duplicate record. var duplicate = false; userModel.find({mobileNumber: 123456789}, (err, user) => { ...

Steps for automatically closing the parent dialog when the child dialog is opened in Material UI React

When utilizing Material UI React, a scenario arises where a dialog opens on button click. Once "yes" is clicked in the initial dialog, another dialog pops up on top of the first one. Is there a way to close the parent dialog before launching the child di ...

What is the purpose of utilizing the npm init command when starting a fresh project?

When I first started learning Front End Development, I began by working on simple projects with just three files: a JavaScript file, an HTML file, and a CSS file. Now, I've learned that in order to start any new project, I need to use the npm init com ...

Express (generator) is failing to load custom scripts located in the public folder

I'm new to node and express and I'm facing a problem. I want to load a custom script.js from the public folder, but it's not loading. There are no errors in the console or anything in the network tab. When I try to access the URL localhost:3 ...

Dealing with Asynchronous JavaScript code in a while loop: Tips and techniques

While attempting to retrieve information from an API using $.getJSON(), I encountered a challenge. The maximum number of results per call is limited to 50, and the API provides a nextPageToken for accessing additional pages. In the code snippet below, my i ...

Validation needed for data list option

Here are all the details <form action="order.php" method="post" name="myForm" onsubmit="return(validate());"> <input type="text" list="From" name="From" autocomplete="off" placeholder="From Place"> <datalist id="From"> <option valu ...

Retrieve information from a database by utilizing AJAX and store it in a JavaScript array

I'm facing an issue where I can retrieve data from the PHP file, but not from the database to my JavaScript code. I am using Ajax to fetch the data from the database, then passing it to the PHP file, and finally trying to filter this data using JavaSc ...

Saving Information to a Specific Location on the Client Side in a CSV File

I am currently working on a static application that uses Angular JS technology. My goal is to write data into a CSV file at a specific path in order for another API to read the data from that location. Despite searching extensively on the internet, I hav ...

Is it possible to circumvent making a double-API call using the getServerSideProps feature in NextJS?

Exploring the workings of NextJS' getServerSideProps, I've noticed an interesting pattern. Upon initially loading a page, the content is fully hydrated. However, upon navigating to a new page, an API call is triggered to fetch JSON data that will ...