I have a strange issue where typescript does not find the types for jszip.
in my source-file I use these imports e.g.
import * as fast_csv from 'fast-csv';
import { Response } from 'express';
import fs from 'fs';
import * as JSZip from 'jszip';
all work fine, except for jszip:

Error:(9, 24) TS7016: Could not find a declaration file for module 'jszip'. 'ROOT/node_modules/jszip/dist/jszip.min.js' implicitly has an 'any' type.
When I look into my (one and only) node_modules/@types dir, all files are there:

here are the relevant entries from package.json
"dependencies": {
"@hapi/joi": "^15.0.1",
"fast-csv": "^2.5.0",
"jszip": "^3.2.1"
},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/hapi__joi": "^15.0.1",
"@types/jszip": "^3.1.6",
}
notes:
jszip it should search for @types/jszip
@hapi/joi are called @types/hapi__joi and they work fine"jszip": "^3.2.1" vs. "@types/jszip": "^3.1.6", right? 
Any idea, what I am missing?
related links:
Update 04.2020
It seems that the issue is fixed in jszip 3.3.0: see Fix browser module resolution #614
Moreover I think the issue was only related to the client side (angular) build. Since node has its own stream package
Original
I found the issue: in tsconfig.json we had an explicit path definition:
"paths": {
"jszip": ["node_modules/jszip/dist/jszip.min.js"],
after removing this, the build failed with:
ERROR in C:/devroot/node_modules/jszip/lib/readable-stream-browser.js
Module not found: Error: Can't resolve 'stream' in 'C:\devroot\node_modules\jszip\lib'
and the solution to this is to install the stream package (thanks to this issue-comment)
npm i stream
or when using typedi:
typedi stream
and now the build works fine.
Note: maybe there is a better way to fix this - see this issue-comment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With