question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v2.0.5 is a breaking change for CommonJS users

See original GitHub issue

I 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 requireing 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:open
  • Created a year ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
DanielJDufourcommented, Apr 14, 2022

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:

const Module = require("module");

const __require__ = Module.prototype.require;

Module.prototype.require = function () {
  try {
    return __require__.apply(this, arguments);
  } catch (error) {
    if (error.message.includes("require() of ES Module")) {
      return {};
    } else {
      throw error;
    }
  }
};

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 with module.exports = , but it’s rather brittle.

Sorry I can’t be more helpful, but I’ll try to brainstorm other solutions, too.

0reactions
DanielJDufourcommented, Aug 29, 2022

I’m using it here: https://github.com/GeoTIFF/geotiff-precise-bbox/blob/main/package.json#L18

    "test": "node -r require-esm-deasync ./test.js",
Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration Guide - Wagmi
You can find the 0.5.x docs here. All the breaking changes in this release are related to the introduction of Prepare Hooks. It...
Read more >
Documentation - TypeScript 4.7
js files are interpreted as ES modules or CommonJS modules, and defaults to CommonJS when not set. When a file is considered an...
Read more >
Issues · geotiffjs/geotiff.js · GitHub
v2.0.5 is a breaking change for CommonJS users. #301 opened Apr 13, 2022 by MichaelBuhler · 7. readRGB returns 3-channel data even for...
Read more >
Webpack breaking change - Stack Overflow
BREAKING CHANGE : webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify...
Read more >
Changelog | Meteor API Docs
Changes; Breaking changes; Migration steps ... hot-module-replacement@0.5.2 ... More data will be retrieved and saved under services.github on the user ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found