esmock: Node 16.12+ breaks esmock

When upgrading to latest node, we’re seeing errors with using esmock.

With some investigation, it looks like 16.12 is the version that broke esmock.

Node 16.12 CHANGELOG

How to reproduce

  1. Check out this repository
  2. nvm use 16.11
  3. npm ci
  4. npm test
  5. Observe tests pass
  6. nvm use 16.12
  7. npm ci
  8. npm test
  9. Observe many test failures

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (12 by maintainers)

Most upvoted comments

I can confirm that the issue has been resolved 👍

Two changes fix this package for the latest versions of node,

  1. The module loader “getSource” definition must be exported as “load”. node shows this in the test process “(node:14251) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getSource”. I searched for ways to conditionally export “getSource” or “load” depending upon the node version but didn’t find a way to it.
  2. The value returned by “load” needs to include a property format: 'module' or an error is thrown.

Here’s what I propose,

  • release a minor version, exporting both ‘load’ and ‘getSource’ hooks. The deprecation warning will show when this package gets used,
  • release a new major version, removing ‘getSource’ and updating the README with some information about that

Maybe “getSource” should be kept rather than removed, I’m not sure.

@mroderick do you have any input?

cc @Swivelgames feel free to give your opinion or ignore as well.