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

geotiff.js polyfill is missing AggregateError for NodeJS v12 #209

Closed aloisklink closed 3 years ago

aloisklink commented 3 years ago

First of all, congrats on release v1.0.0 of geotiff.js!

I'm having an issue when trying to use the new version 1.0.0 of geotiff.js in Node v12. It looks like dist-node/geotiff.js does not correctly export AggregateError, and instead creates some invalid Javascript code, (e.g. const h=void 0===h?g:h; which fails with ReferenceError: Cannot access 'h' before initialization ) for the line:

https://github.com/geotiffjs/geotiff.js/blob/c01b2dcf00d5a324cd27c38709cb6ca97adf01e2/src/utils.js#L159

I believe this is because babel/parcel is rewriting export const AggregateError = AggregateError; to const x = x; exports.x = x; which is invalid JavaScript.

Potential fixes

We can fix it by renaming the export so it's not the same as AggregateError: (e.g. export const PolyfilledAggregateError = ...).

Or better yet, if you install core-js: "^3.9" and change your .babelrc file to the following, Babel should automatically add AggregateError to the dist-node folder, so you don't need to make your own version:

{
  "presets": [
    ["@babel/preset-env",
      {"useBuiltIns": "usage", "corejs": {"version": "3.9", "proposals": true}}
    ]
  ],
  "plugins": ["@babel/plugin-transform-runtime"]
}
aloisklink commented 3 years ago

Fixed by 57e089c1204098616201dfc7d0ceb0b4410e9a73 in v1.0.1! Thanks @constantinius! :)