How to fix JavaScript error in VKontakte, Discord and other applications

If you see a failure warning on your monitor, it means your Discord voice chat has stopped working due to the error “JavaScript error occurred in the main process”. This is one of the many errors in the Windows operating system. It is used to indicate a failure in a specific area or program. Many errors can be corrected with simple step-by-step steps. But some can’t be fixed on your own; you need to seek qualified help from a specialist. Below we will look at how to fix the Javascript error occurs error.

JavaScript error screenshot

What is the error, why does it occur and where does it occur?

Situation: a user goes to the VKontakte website and discovers that video files and audio recordings have stopped playing . At the top left of the page, the message “JavaScript error: initAddMedia is not defined” is displayed, indicating a JavaScript syntax error: initAddMedia. The causes of the problem, as well as the text of the message, may be different, and to solve it you will have to try several methods.

Type of error

A similar error occurs in the Discord client : “JavaScript error occurred in the main process” (an error occurred in the main process).

Process error

Regardless of the program and message, it can occur for several reasons:

  • conflict of the process with other running programs;
  • the remaining files of the old version of the client conflict with the working one;
  • lack of Windows updates
  • infection .

Quick solution to the problem

To quickly resolve the JavaScript error, we will disable autoloading in the settings of Skype itself. And then add the program to the Windows startup folder. In 99% of cases this will be enough.

  1. Open Skype. Click on the three dots icon.
  2. Select the “Settings” item.
  3. Next, go to the “General” tab and turn off the “Start Skype automatically” option.

    Disable Start Skype automatically

    Disable Start Skype automatically

  4. Now we need to return the program to autorun.
  5. Click “Start” and look for the “Startup” item.
    There we drag the icon from the Desktop or from the Skype folder in the programs section. Drag the program icon to Startup
  6. Restart the operating system and check if the error disappears.

How to fix the VKontakte error

There are 3 main ways to fix the problem.

Cleaning hosts

The user requires a few simple steps:

  1. Open My Computer , then the Windows/system32 , then the driver folder, after etc.
  2. In the etc directory open hosts file through any text editor (use the context menu to find the line “To open with" and select the appropriate program).

    open hosts file

  3. All that should be in the file is the line 127.0.0.1 localhost . If there is anything else, it is junk that is preventing audio and video files from playing. You need to delete everything, leaving the line 127.0.0.1 localhost, then save the changes.
  4. Restart your PC.

Java and Adobe Flash Player Update

You should go to the official Java and Adobe websites and download the latest versions of the programs.

Fixing d3dcompiler43 dll error

Clearing the browser cache

The combination Ctrl + F5 will clear the cache of the browser page currently open. You need to open the VKontakte website and press these keys. The page will be completely reloaded , ignoring caching.

It's better to clear your entire browser cache , not just the cache of one page. To do this, press the combination Ctrl + H , after which a window with the browser history will open. Next, find the line “ clear history ”. To clear browser caches, you can also use third-party programs, for example, Ccleaner.

Clearing cache

Asynchronous mechanisms - promises

To perform asynchronous operations in JavaScript, it is better to use promises rather than callbacks. Here, in addition to improved code readability, there are also more advanced error handling mechanisms. Namely, there is no need to mess around with an error object that might end up in a callback function when using promises. Here a special catch block is provided for this purpose. It catches all errors that occurred in promises that come before it, or all errors that occurred in the code after the previous catch block. Note that if there is an error in the promise that there is no catch block to handle, this will not stop the script from executing, but the error message will not be particularly readable.

As a result, we can always recommend using a catch block when working with promises. Let's look at an example.

How to fix an error in Discord

The Discord client sometimes experiences a "JavaScript error occurred in the main process" problem. Below we will describe two ways to deal with it when launching Discord. At least one method will definitely work, so if one doesn’t help, you should definitely try the second.

Client update

Sometimes this problem occurs due to the need for an update, even though automatic program updates were disabled for some reason. You should update the client yourself by following the instructions below:

  1. Open Task Manager , disable all processes related to Discord.
  2. Click combination Win + R and type %AppData%.

    Run window

  3. Exit back from Roaming to AppData .
  4. Next, go to the Local and find the Discord folder in it.
  5. Double-click on Update.exe , which initiates the program update.
  6. Turn on Discord.

After completing all the steps, the program will be updated upon startup. Once the update installation is complete, you should check to see if this issue no longer occurs. If it continues to appear, you need to proceed to the second method.

Reinstalling the client

If the first method does not help (it really only helps in a minority of cases), the only option left is to completely remove the program and clean install it. To do this, you need to perform the following sequence of actions:

  1. Open Task Manager , disable all processes related to Discord.
  2. In the Control Panel , find Programs and Features and open.
  3. Find the line with the word Discord and delete it, then repeat steps 2-4 from the previous method to find the Discord directory and delete it. Then go to AppData , go to Roaming and also delete the folder called Discord.
  4. Reinstall the Discord client .

How to resolve the Missing operating system error

other methods

If the error still does not go away, then all that remains is to check the system for viruses and install the latest Windows system updates.

If a JavaScript error occurs in other programs or on the Internet, which is much less common, then all the methods described above will work. In the case of applications, you can perform the same actions as with Discord, but for the desired program.

System errors¶

System errors are generated when exceptions are thrown in the program's execution environment. These are typically operational errors that occur when an application exploits OS restrictions, such as trying to read a file that does not exist, or when the user does not have sufficient rights.

System errors are usually generated at the system call level: a complete list of error codes and their meanings is available by running man 2 intro or man 3 errno on most Unix systems, or online.

In Node.js, system errors are Error objects with additional properties.

System Error¶ Class

error.code error.errno

Returns a string containing the error code, which is always an E followed by a set of capital letters and may refer to the man 2 intro.

The error.code and error.errno properties complement each other and return the same value.

error.syscall¶

Returns a string describing a failed system call.

Basic system errors¶

This list is not complete, but contains most of the main system errors that developers most often encounter when writing a program in Node.js.
EACCES An attempt was made to access a file that was denied by permissions. EADDRINUSE (Address already in use) An attempt to bind a server (net, htttp, https) to a local address failed because another server on the local system already occupies this address. ECONNREFUSED The connection cannot be made because the target computer is actively rejecting it. This is usually the result of attempts to connect to an inactive server on someone else's host. ECONNRESET (Connection reset by peer) The connection was forcibly closed by the peer. Typically the result of a connection loss on the remote socket due to a timeout or reboot. Mainly found on http and net modules. EEXIST (File Exists) The operation retrieved an existing file when it wanted to retrieve a non-existent one. EISDIR (This is a directory) The operation expected a file, but the given path is a directory path. EMFILE (Too many open files on system) The maximum number of file descriptors allowed by the system has been reached, requests to other descriptors cannot be completed until at least one is closed. This happens when you have a large number of files open at the same time, especially on systems (such as OS X) that have a small limit on file descriptors for processes. To configure the limit, run ulimit -n 2048 in the same shell where the Node.js process is running. ENOENT (No such file or directory) Typically thrown by fs operations to indicate that a component of the given path does not exist - the file or directory cannot be found at the given path. ENOTDIR (Not a directory) A component of the specified path exists, but is not a directory. Often dropped from fs.readdir. ENOTEMPTY (Directory is not empty) The target of the operation was an empty directory, but the result was a non-empty directory (often fs.unlink). EPERM (Operation Not Permitted) An attempt was made to perform an operation that requires special access rights. EPIPE (Pipe Problems) Writing to a pipe, socket, or FIFO that does not have a process to read the data. Typically found on the net and http side, indicating that the remote side of the stream being recorded is closed. ETIMEDOUT (Operation timed out) The connection or sending of the request failed because the party to which the connection is being made is not responding. Occurs in net or http, often signaling that socket.end() was called incorrectly.

Other error options

The methods for correcting all errors are identical, but sometimes it is not necessary to correct them; the main thing is to understand what exactly the application or service is warning about:

  1. A fatal JavaScript error occurred ” – occurs in Discord, the application crashes. This can be fixed by updating or completely reinstalling the client. If this does not help, you need to check the program with an antivirus, first disabling all Discord processes, then run the program as an administrator.
  2. JavaScript error: data is not a function ” (data is not a function) – occurs in VK, messages do not open. Clearing the browser cache usually helps.
  3. JavaScript error : wall is not defined ” (wall is not defined) – appears on VKontakte when the page is refreshed, the wall stops working. Solved by updating Java, Adobe Flash Player, clearing the hosts file, clearing the browser cache and restarting the PC.
  4. JavaScript error: poster is not defined ” (poster is not defined), “ JavaScript error: mediaselector is not defined ” (media selector is not defined) – VKontakte errors, and you cannot view news and messages. Usually solved by updating the browser, Java or Flash Player.
  5. JavaScript error: scrollnode is not defined ” (node ​​is not defined) – VK error. It cannot be fixed; the problem is on the server side.
  6. JavaScript error: profile is not defined ” (profile is not defined) – VK error, VKontakte pages open incorrectly. To fix it, you need to clear the cache and hosts file and restart the computer.

What to do if the local system service node is loading the disk and processor

In general, the methods for correcting all JavaScript errors are identical, they are also relevant for the following decryptions: timespent is not defined, mutations are not initialized, uisearch is not defined, upload is not defined, object is not a function, getaudioplayer updatecurrentplaying and others.

Class SyntaxError¶

An Error subclass that indicates that the program is not valid for JavaScript. These errors are generated and propagated only as a result of code evaluation. Code evaluation can be called by eval, Function, require or vm. These errors are almost always indicators of a malfunctioning program.

try { require('vm').runInThisContext('binary ! isNotOk'); } catch (err) { // err will be a SyntaxError }

SyntaxError instances are not restored in the contest in which they were created. They can only be captured by another context.

Routing

Now that our error object is ready to be used, we need to set up our route structure. As mentioned above, we need to implement a unified approach to error handling that allows us to handle errors equally for all routes. By default, the Express.js framework does not fully support this scheme of work. The fact is that all its routes are encapsulated.

To deal with this problem, we can implement our own route handler and define the route logic as regular functions. With this approach, if the route function (or any other function) throws an error, it will be passed to the route handler, which can then pass it to the client side of the application. When an error occurs on the server, we plan to pass it to the frontend in the following format, assuming that the JSON-API will be used for this:

If at this stage what is happening seems unclear to you, don’t worry - just keep reading, try to work with what is being said, and gradually you will understand everything. In fact, when it comes to computer training, it takes a top-down approach, discussing general ideas first and then moving on to specifics.

This is what the route handler code looks like.

We believe that the comments in the code explain it quite well. We hope they are easier to read than the explanations of similar code given after it.

Now let's take a look at the routes file.

In these examples, nothing is done to the queries themselves. Here we simply consider different error scenarios. So, for example, a GET /city request will go into the const GET = req =>... function, a POST /city request will go into the const POST = req =>... function, and so on. This scheme also works when using query parameters. For example, for a request like GET /city?startsWith=R. In general, it demonstrates that when handling errors, the frontend can receive either a general error containing only a suggestion to try again or contact the server owner, or an error generated using the CustomError constructor, which contains detailed information about the problem. The general error data will come to the client part of the application in the following form:

The CustomError constructor is used like this:

This produces the following JSON code passed to the frontend:

Now that we have thoroughly worked on the server side of the application, useless error logs no longer appear on the client side. Instead, the client receives useful information about what went wrong.

Don't forget that there is a repository for the code discussed here. You can download it, experiment with it, and, if necessary, adapt it to the needs of your project.

Now it’s time to describe the third part of our error handling system, relating to the frontend. Here you will need, firstly, to handle errors that occur in the client part of the application, and secondly, you will need to notify the user about errors that occur on the server. Let's first look at displaying information about server errors. As already mentioned, this example will use the React library.

Rating
( 1 rating, average 4 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]