eugeneware / ffmpeg-static

ffmpeg static binaries for Mac OSX and Linux and Windows
GNU General Public License v3.0
1.07k stars 175 forks source link

Build error - ffmpeg path not assignable to type string #115

Closed mrn closed 2 years ago

mrn commented 2 years ago

When compiling a typescript project, I get this error:

src/.../file.ts:139:24 - error TS2345: Argument of type 'typeof import("/Users/me/project/node_modules/ffmpeg-static/types/index")' is not assignable to parameter of type 'string'.

139         .setFfmpegPath(ffmpegPath)
                           ~~~~~~~~~~

The import:

import * as ffmpegPath from "ffmpeg-static";

What's causing this? I did a clean install of all packages, which didn't help.

My colleague can compile it without the error.

Some package versions:

─ ffmpeg-static@5.1.0
─ ffprobe-static@3.1.0
─ @types/ffmpeg-static@3.0.1
─ @types/ffprobe-static@2.0.1
─ typescript@4.7.3
derhuerst commented 2 years ago
src/.../file.ts:139:24 - error TS2345: Argument of type 'typeof import("/Users/me/project/node_modules/ffmpeg-static/types/index")' is not assignable to parameter of type 'string'.

139         .setFfmpegPath(ffmpegPath)
                           ~~~~~~~~~~

This is weird, as the typings clearly say that it exports a string: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/2e051a5f3e3a28d405d447fbed9b73009a5e63c7/types/ffmpeg-static/index.d.ts

What's causing this? I did a clean install of all packages, which didn't help.

My colleague can compile it without the error.

That sounds a lot like the error is caused by your environments. Double-check that

mrn commented 2 years ago

Interesting, my ffmpeg-static/types/index.d.ts is this:

declare const ffmpegPath: string | null;
export default ffmpegPath;

The versions are from package.json

mrn commented 2 years ago

I have no idea what caused that, but I recreated the project (deleted, cloned the repo, installed npm packages) and now the same version of @types/ffmpeg-static declares ffmpegPath as only a string.

derhuerst commented 2 years ago

This is weird, as the typings clearly say that it exports a string: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/2e051a5f3e3a28d405d447fbed9b73009a5e63c7/types/ffmpeg-static/index.d.ts

As you pointed out, my statement was wrong: As of f63f44ce95cd991bb05e5b44191788c3f9341ea2, ffmpeg-static bundles the type declarations by itself:

https://github.com/eugeneware/ffmpeg-static/blob/dce6d42ba772a5769df8181e704772db4456ef16/types/index.d.ts

Nevertheless, glad that it works now.

minimusubi commented 2 years ago

I've just run into the same issue, using:

ffmpeg-static@5.1.0
typescript@4.8.3

Curiously, the old @types/ffmpeg-static package exported the type as

declare const ffmpegPath: string | null;
export = ffmpegPath;

However, this package exports it as

declare const ffmpegPath: string | null;
export default ffmpegPath;

Note the = and default. If I change my local index.d.ts file within this package to use =, the error goes away.

Edit: Minimum repro repo results in

error TS2322: Type 'typeof import("C:/Users/me/Workspace/ffmpeg-static-115/node_modules/ffmpeg-static/types/index")' is not assignable to type 'string'.
derhuerst commented 2 years ago

If you know of a fix, please submit a PR. Thanks!