[Fixed] node npm error code Z_DATA_ERROR errno -3 zlib: incorrect data check – Node.js

by
Ali Hasan
node.js react-typescript

Quick Fix: Downgrade to Node v14.17 and fix any errors in your JS project before migrating to TS.

The Problem:

The user is facing an error while running tsc on their typescript project. They are getting the following error:

npm ERR! code Z_DATA_ERROR npm ERR! errno -3 npm ERR! zlib: incorrect data check

The Solutions:

Solution 1: Downgrade Node.js and reinstall TypeScript

Explanation:

A bug in the latest Node.js version can cause "zlib: incorrect data check" errors during npm installations. To resolve this issue:

  1. Install Node Version Manager (nvm), if not already installed.
  2. Downgrade to Node.js version 14.17 using nvm by running nvm install 14.17 and nvm alias default 14.17.
  3. Reinstall TypeScript using npm install typescript --save-dev.
  4. Ensure your JS project builds successfully.
  5. Edit the tsconfig.json file according to TypeScript’s migration guide and run tsc.

This should resolve the "zlib: incorrect data check" error and allow you to build TypeScript projects successfully.

Q&A

Why did I get a zlib: incorrect data check error when running npm?

There may be a bug in the most recent version of node. Downgrade to node 14.17 and try again.

What is the full error in question?

npm ERR! code Z_DATA_ERROR pm ERR! errno -3 npm ERR! zlib: incorrect data check