ExifReader icon indicating copy to clipboard operation
ExifReader copied to clipboard

Custom Build not picked up from TypeScript import

Open Jonarod opened this issue 1 year ago • 2 comments

Description

When imported from TypeScript file, the full build is imported instead of the custom one.

Additional details

  • ExifReader version: 4.23.7
  • Web browser and version: Chrome
  • Node version: 20.3.0

How to reproduce

  1. Create a TypeScript project using Vite
  2. Add some 'include tags in the exifreader field of package.json:
  "exifreader": {
    "include": {
      "exif": [
        "GPSLatitude",
        "GPSLatitudeRef",
        "GPSLongitude",
        "GPSLongitudeRef",
        "GPSAltitude",
        "GPSAltitudeRef"
      ]
    }
  }
  1. npm rebuild exifreader && rm -rf node_modules/.vite
  2. In some Typescript file: import ExifReader from 'exifreader';

What I expected would happen:

I expected to see only the tags I included.

What really happened:

Every tags were loaded instead.

My guess is that instead of looking for the node_modules/exifreader/dist/exif-reader.js file, TypeScript directly tries to load node_modules/exifreader/exif-reader.d.ts and then loads the full build instead of the custom build.

Jonarod avatar Oct 23 '24 16:10 Jonarod

I was able to bypass this using a direct import of the custom build:

/* @ts-ignore */
import ExifReader from 'exifreader/dist/exif-reader.js';

The /* @ts-ignore */ is not excellent resolution for the purists but it made my day for now :)

Leaving this open as I consider this a bug for TypeScript users, but feel free to close it.

Jonarod avatar Oct 23 '24 16:10 Jonarod

Hi!

I think the issue is that it will always look at the module property in package.json which points to the main entry file, not the built file. You could try changing the compilerOptions.moduleResolution value in your tsconfig.json and see if that helps.

The package.json should use the exports property instead which could help solve this issue, but I think that is an update for the next major version.

mattiasw avatar Oct 24 '24 17:10 mattiasw