TmTron
TmTron

Reputation: 19391

typescript does not find jszip types

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: es

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: enter image description here

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:

Any idea, what I am missing?

related links:

Upvotes: 3

Views: 10276

Answers (1)

TmTron
TmTron

Reputation: 19391

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

Upvotes: 1

Related Questions