v2.0.5 is a breaking change for CommonJS users
See original GitHub issueI think the code in v2.0.5 is a breaking change for CommonJS users, such as my organization.
The underlying cause is because of the quick-lru
dependency that was added is ESM only.
I guess more broadly, anyone who is require
ing geotiff
in a CommonJS package with see a failure with geotiff@2.0.5
because Node cannot require
the quick-lru
module in geotiff.js/dist-module/source/blockedsource.js
around line 7. They will see an error message, such as:
/path/to/code/node_modules/geotiff/dist-node/source/blockedsource.js:7
const quick_lru_1 = __importDefault(require("quick-lru"));
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/code/node_modules/quick-lru/index.js from /path/to/code/node_modules/geotiff/dist-node/source/blockedsource.js not supported.
Instead change the require of index.js in /path/to/code/node_modules/geotiff/dist-node/source/blockedsource.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/path/to/code/node_modules/geotiff/dist-node/source/blockedsource.js:7:37)
at Object.<anonymous> (/path/to/code/node_modules/geotiff/dist-node/source/remote.js:6:28)
at Object.<anonymous> (/path/to/code/node_modules/geotiff/dist-node/geotiff.js:33:21)
... {
code: 'ERR_REQUIRE_ESM'
}
Not sure how to proceed here, maybe a warning should be added to release notes or something.
Also (I don’t have a lot of knowledge in this area), is there any advantage to building and distributing the dist-node
folder if you have to use ESM imports now?
Another option is to downgrade quick-lru
to v5.1.1
as the ESM breaking change is in v6.0.0
. See here.
Refactoring my whole app to "type": "module"
probably can’t happen soon, so I will miss out on some good features slated for the next release (v2.0.6 perhaps).
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:7 (5 by maintainers)
I ran into this issue as well. I use geotiff as a nested dependency in geomask. It’s far from a workaround for general use, but I got around this issue by basically returning an empty object from require when it hits an ESM Import error. I’m providing the solution here in case it is enough for your use case:
see https://github.com/DanielJDufour/geomask/blob/main/require-esm-as-empty-object.js:
I too am hoping for a more general solution because I use geotiffjs in tens of small libraries and converting everything to ES6 would be a pain (as well as potentially causing issues for other users).
fwiw, I’ve had some success in the past converting ESM syntax to CJS syntax doing string replaces (replacing
export default
withmodule.exports =
, but it’s rather brittle.Sorry I can’t be more helpful, but I’ll try to brainstorm other solutions, too.
I’m using it here: https://github.com/GeoTIFF/geotiff-precise-bbox/blob/main/package.json#L18