webrecorder / warcio.js

JS Streaming WARC IO optimized for Browser and Node
MIT License
30 stars 6 forks source link

tsc build issue when including warcio in esm project #66

Open andrewmackrodt opened 7 months ago

andrewmackrodt commented 7 months ago

I'm including warcio in an ESM Node.js 20 monorepo with TypeScript 5.3.2 and am experiencing build failure when running tsc --build. The relevant tsconfig.json entries are:

  "compilerOptions": {
    "module": "Node16",
    "moduleResolution": "Node16",

The error is:

../../node_modules/warcio/dist/index.d.ts(2,25): error TS2307: Cannot find module 'hash-wasm/dist/lib/WASMInterface' or its corresponding type declarations.
../../node_modules/warcio/dist/warcserializer-48f5a2a4.d.ts(1,25): error TS2307: Cannot find module 'hash-wasm/dist/lib/WASMInterface' or its corresponding type declarations.

Adding .js suffix to the IHasher import fixes the issue although I don't know how that would affect cjs builds: https://github.com/webrecorder/warcio.js/blob/397c2a6e319c9a8c1e28e7d6ea6113dc12eb3049/src/lib/warcserializer.ts#L6

andrewmackrodt commented 7 months ago

For now I've managed to work around this issue by creating the file (and updating my tsconfig typeRoots):

types/hash-wasm/index.d.ts:

declare module 'hash-wasm/dist/lib/WASMInterface' {
    export type { IHasher } from 'hash-wasm/dist/lib/WASMInterface.js'
}

Some other dependency issues are covered in https://github.com/webrecorder/warcio.js/pull/64, e.g. I've added the following devDependencies to my project:

    "@types/pako": "^1.0.0",
    "@types/stream-buffers": "^3.0.4"