Yahweasel / libav.js

This is a compilation of the libraries associated with handling audio and video in ffmpeg—libavformat, libavcodec, libavfilter, libavutil, libswresample, and libswscale—for emscripten, and thus the web.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not find a declaration file for module '@libav.js/variant-webcodecs-avf'

lucadalli opened this issue · comments

Could not find a declaration file for module '@libav.js/variant-webcodecs-avf'. '[redacted]/libav-types-error/node_modules/@libav.js/variant-webcodecs-avf/dist/libav-webcodecs-avf.mjs' implicitly has an 'any' type.
  There are types at '[redacted]/libav-types-error/node_modules/@libav.js/variant-webcodecs-avf/dist/libav.types.d.ts', but this result could not be resolved when respecting package.json "exports". The '@libav.js/variant-webcodecs-avf' library may need to update its package.json or typings.ts(7016)

I am facing the error above when importing libav.js or any of the variant packages into my Nuxt project.
I am very ignorant about bundlers and their configuration but have prepared a minimal repro at lucadalli/libav-types-error

One way to fix the error is to add a types field to package.json exports

    "import": "./dist/libav-webcodecs-avf.mjs",
    "default": "./dist/libav-webcodecs-avf.js",
    "types": "./dist/libav.types.d.ts"
  },

and importing the types like so:

import type * as LibAVJS from "@libav.js/variant-webcodecs-avf";
declare let LibAV: LibAVJS.LibAVWrapper;

Is this some horrendous TypeScript change? If types are not specified by an export, it's supposed to look in the global types specification. This nonsense about "can't use that while respecting exports" is utterly bizarre; no one should have to respecify the types file in the exports when it's already specified globally. I use the variant packages with many TypeScript projects and none of them complain in this way.

Unfortunately I have never properly authored a public-facing package so I'm not so well-versed about the proper way to define a package.json. What you're saying makes sense to me but that error does explicitly state that it found the types by using the main types field but could not respect it because it's missing from exports.types.
I am seeing this error in VSCode only when I enable strict: true in the tsconfig.json compilerOptions as per the minimal repro.

Is strict enabled in any of your Typescript projects?

Yes. What I've never seen before is moduleResolution "Bundler". I have no idea what that means. The normal module resolution is "node" (or "nodenext" or "node6" etc etc etc)