How to analyze the root cause of an error after running commands such as NPM update

Source: Internet
Author: User

When I work today, execute the command NPM update in the working directory of the current front-end project
The following error is returned: registry error parsing JSON
NPM Err! Unexpected token <in JSON at position 0

Some of my friends are overwhelmed by this mistake.
This article describes how to analyze the errors reported by the NPM command.

First, an error occurs when NPM parses a JSON response according to the error message, because the first character of the expected JSON response is <.

So where does the JSON Response Request come from?

We need to view the help documentation for the command NPM update.

Run the command line NPM help NPM to open the help document after NPM is installed locally:

If no specific package name is specified after NPM update, all dependent packages listed in package. JSON will be updated to the latest version.

Let's look at the last line of NPM update error output, listing a log file, including the error details.

An error occurred when the JSON file is described in the SAP/n package of the Request dependency package:

This request. js file is useful in the NPM global installation directory:
"C: \ Users \ i038516 \ appdata \ roaming \ NPM \ node_modules \ NPM-registry-client \ Lib \ request. js"
It is the JSON file that NPM initiates an HTTP request to fetch the SAP/N dependent package.

We add some debugging information to the callback function of the JSON request:

Now it is clear that there is a problem with the remote end of the dependent package SAP/n. Contact the owner of the dependent package to fix the problem.

As a temporary alternative, you can also delete the dependent package that causes the problem from package. JSON, and then NPM update will work normally.

For more original Jerry articles, follow the Public Account "Wang zixi ":

How to analyze the root cause of an error after running commands such as NPM update

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.