Error when install express-generator using npm

21.7k views Asked by At

I tried to install express-generator using the command npm install express-generator but I get the following error. I searched in the web and could not find any helpful answers for this.

npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm ERR! Unexpected end of JSON input while parsing near '...DHZShvBYWKIIktsiBUuRD'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ASUS\AppData\Roaming\npm-cache\_logs\2020-07-12T10_29_10_754Z-debug.log
3

There are 3 answers

0
ffflabs On

The WARN has nothing to do with the rest of the message. It's only that, a WARN, and it should be given to package mantainers using outdated deps, not you.

The ERR(s) is saying npm could not parse a JSON content somewhere and not much else.

Before digging into the logfile it's showing you, try cleaning your cache to cover the not uncommon case in which a cache entry is corrupted or inconsistent and npm crashes just because it's trying to be more efficient.

Given you're using window, open a console as administrator (both CMD and Powershell should work, but I don't have a windows machine atm) and run

npm cache clean --force

Alternatively, running

npm doctor

Will, among other checks, verify the cached packages and pinpoint the corrupt or inconsistent ones.

It wouldn't hurt to also update your npm version to the latest one using

npm install -g npm

When you're done, try running express-generator again.

0
Sanskar Gupta On

Check my method below!! It worked for me

  1. Disable protections
    npm cache clean --force
  1. Run a set of checks to ensure that your npm installation has what it needs to manage your JavaScript packages.
    npm doctor
  1. Now, Globally install the Node Package Manager (npm) itself, ensuring you have the latest version available system-wide
    npm install -g npm

Check my below screenshot for reference VS Code Terminal image

0
msc On

If you are struggling with installing express-generator global version with npm but if there is a problem with the node and npm version, you might give try to downgrade your node version. In my case, the solution below worked:

Firstly install nvm (node version manager) by following the README.md instructions from here.

If it's installed properly, you can give it a try by typing simply command -v nvm. If it returned nvm it's been installed successfully.

As I said, in my case, I tried an older version (14.20.0).

1- First, install older node version nvm install 14.20.0

2- Then switch to that version by typing nvm use 14.20.0.

2.1.- If delete-prefix related error occur, simply type nvm use --delete-prefix v14.20.0.

3- Install express-generator global version now by typing npm install -g express-generator. After it's installed successfully you can simply switch back to the newer version as the same method as we used above nvm use 16.17.0. (In my time, latest stable method is 16.17.0 so I switched back to that version, you can switch whatever version you want to use)

I hope this approach works for you.