Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type definition export #33

Closed
Brakebein opened this issue Dec 28, 2023 · 5 comments
Closed

Wrong type definition export #33

Brakebein opened this issue Dec 28, 2023 · 5 comments

Comments

@Brakebein
Copy link

The current export of the type definition in index.d.ts looks like this:

export default function exif(buffer: Buffer): Exif;

However, the current implementation in index.js does not export any default. The type definition should actually look like this (similar to the old type definitions):

declare function exif(buffer: Buffer): Exif;
export = exif;

or you need to adapt the exports in index.js appropriately.

When I import the library using import exifReader from 'exif-reader'; I will get following runtime error:

(0 , exif_reader_1.default) is not a function

It only works when I import and use it the following way:

import * as exifReader from 'exif-reader';

const metadata = await sharp(file).metadata();
 // @ts-ignore
const exif = exifReader(metadata.exif);

(I cannot set "esModuleInterop": true in tsconfig due to some other library.)

@radarlog
Copy link

radarlog commented Jul 9, 2024

Can confirm the same.

I found another workaround:

import exifRead from 'exif-reader';

// https://github.com/microsoft/TypeScript/issues/52086#issuecomment-1385978414
export const readExif = exifRead as unknown as typeof exifRead.default;

@atombrenner
Copy link
Contributor

@Brakebein Can you share your tsconfig.json? I can confirm that the current typing is incorrect, I am just curious why it does not cause problems in my projects. (And sorry for the very late response 😊 )

@Brakebein
Copy link
Author

I have a monorepo with a tsconfig.base.json like this:

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2017", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
  },
  "exclude": ["node_modules", "tmp"]
}

and tsconfig.app.json for the respective app:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist",
    "module": "commonjs",
    "types": ["node"],
    "emitDecoratorMetadata": true,
    "target": "es2015"
  },
  "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
  "include": ["src/**/*.ts"]
}

@atombrenner
Copy link
Contributor

I have created a PR to fix the problem.

@lovell
Copy link
Collaborator

lovell commented Jan 14, 2025

Fix published in v2.0.2

@lovell lovell closed this as completed Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants