geotiffjs / geotiff.js

geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.
https://geotiffjs.github.io/
MIT License
878 stars 183 forks source link

require not working with dist-node #338

Open CutiePi opened 1 year ago

CutiePi commented 1 year ago

dist-node should work with require but it complains with import errors on a sub dependency.


Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/jasmin/projects/solargraf-api/node_modules/quick-lru/index.js
require() of ES modules is not supported.
require() of /home/jasmin/projects/solargraf-api/node_modules/quick-lru/index.js from /home/jasmin/projects/solargraf-api/node_modules/geotiff/dist-node/source/blockedsource.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/jasmin/projects/solargraf-api/node_modules/quick-lru/package.json.
CutiePi commented 1 year ago

Not sure if I'm missing something. I expect the node-dist to work with const GeoTIFF = require('geotiff'); as is.

CutiePi commented 1 year ago

Note we were using an older version and it works.

zhanghjtx commented 1 year ago

I aslo have same question, and use nestjs to import it also exist.