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
860 stars 181 forks source link

Build failing after geotiff release 2.0.5 #292

Closed ZakarFin closed 2 years ago

ZakarFin commented 2 years ago

We use OpenLayers as a dependency (which uses geotiff as dependency "geotiff": "^2.0.2") and our builds started failing (Jest transform issue) after the very recent 2.0.5 release of geotiff. It works if I declare the older 2.0.4 version to be used on our dependencies: https://github.com/oskariorg/oskari-frontend/pull/1779.

Any suggestions on how to fix this to work with geotiff 2.0.5?

Here's what Jest reports on our CI build:


FAIL bundles/mapping/mapmodule/plugin/markers/MarkersPlugin.ol.test.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /home/runner/work/oskari-frontend/oskari-frontend/node_modules/geotiff/node_modules/quick-lru/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export default class QuickLRU extends Map {
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:[172](https://github.com/oskariorg/oskari-frontend/runs/5641986611?check_suite_focus=true#step:6:172)8:14)
      at Object.<anonymous> (node_modules/geotiff/dist-module/source/blockedsource.js:1:1)
mmomtchev commented 2 years ago

Add this to your jest.config.js:

module.exports = {
    transform: {
        '^.+\.(t|j)sx?$': 'ts-jest'
    },
    transformIgnorePatterns: ['/node_modules/(?!(ol|geotiff|quick-lru))']
};

However this is but the beginning of your problems since quick-lru triggers another problem in jest - linked to Symbol.toStringTag

mmomtchev commented 2 years ago

@ZakarFin solved by https://github.com/sindresorhus/quick-lru/pull/39

constantinius commented 2 years ago

@mmomtchev @ZakarFin is there an action required for geotiff.js as well?

mmomtchev commented 2 years ago

@constantinius you can probably bump the quick-lru version number in your package.json but since you are using semver ^, a new install will use the new version anyway

ZakarFin commented 2 years ago

Thanks everyone! Looks like adding both geotiff and quick-lru to Jest-config makes this work now: https://github.com/oskariorg/oskari-frontend/pull/1792