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:
- Install Node Version Manager (nvm), if not already installed.
- Downgrade to Node.js version 14.17 using nvm by running
nvm install 14.17
andnvm alias default 14.17
. - Reinstall TypeScript using
npm install typescript --save-dev
. - Ensure your JS project builds successfully.
- Edit the
tsconfig.json
file according to TypeScript’s migration guide and runtsc
.
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