Custom Build not picked up from TypeScript import
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
- Create a TypeScript project using Vite
- Add some
'includetags in theexifreaderfield ofpackage.json:
"exifreader": {
"include": {
"exif": [
"GPSLatitude",
"GPSLatitudeRef",
"GPSLongitude",
"GPSLongitudeRef",
"GPSAltitude",
"GPSAltitudeRef"
]
}
}
-
npm rebuild exifreader && rm -rf node_modules/.vite - 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.
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.
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.