Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 16.12+ breaks esmock #16

Closed
mroderick opened this issue Oct 27, 2021 · 17 comments · Fixed by #17
Closed

Node 16.12+ breaks esmock #16

mroderick opened this issue Oct 27, 2021 · 17 comments · Fixed by #17

Comments

@mroderick
Copy link

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
@iambumblehead
Copy link
Owner

@mroderick thanks for messaging me here. I'll take a look this evening to try resolving this.

@iambumblehead
Copy link
Owner

iambumblehead commented Oct 28, 2021

The mac+node issue described here affects me (though they are discussing a different version) https://stackoverflow.com/questions/69452504/zlib-error-when-attempting-to-run-npm-install-or-yarn#answer-69743293

I'll need to resolve environment issues before I can look into this

@iambumblehead
Copy link
Owner

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.

@iambumblehead
Copy link
Owner

the PR auto-closed this ticket...

@iambumblehead
Copy link
Owner

its published as version 0.4.2 https://www.npmjs.com/package/esmock

feel free to re-open this issue @mroderick

I didn't intend close the issue but wrote 'closes #16' in the PR description and github closed it. Anyway, I think its resolved.

@maherma-adg
Copy link

With version esmock@1.0.0 on 16.13.0 you get this warning:
(node:13737) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getSource

@iambumblehead
Copy link
Owner

iambumblehead commented Nov 6, 2021

@maherma-adg do you recommend a way to resolve this? I searched for a way to conditionally export 'getSource' if node version is less than 16.12, but node forces the file to declare exports statically.

what do you think of think of this idea... two module loaders, one for node v12-v16.11 and another for node v16.13+

node v12-v16.11

mocha --loader=esmock/loader.getSource.mjs

node v16.12+

mocha --loader=esmock

I'm not exactly sure if it will work, but I think it could work.

@iambumblehead
Copy link
Owner

I would prefer if "--loader=esmock" could be used always but how does one make that load a file that only exports "getSource" for node v12-v16.11?

@iambumblehead
Copy link
Owner

@maherma-adg I found a way to make the warning go away #19

@iambumblehead
Copy link
Owner

@maherma-adg try the newest version

@mroderick
Copy link
Author

I can confirm that the issue has been resolved 👍

@maherma-adg
Copy link

It's works with ava, but I can't make it work with jest, anyone can?

@iambumblehead
Copy link
Owner

@maherma-adg I haven't tried it with jest, but doesn't jest process everything through a transpiler? Maybe that's why it doesn't work... maybe its transforming the sources into cjs or something similar

@maherma-adg
Copy link

maherma-adg commented Nov 12, 2021

As far as I know, jest only transpile when needed ( and you must configure transpiler ) for TS, Vue, JSX, etc. I'll try to dig deeper.
Thanks for your useful tool.
Manuel.

UPDATE: My mistake, reading more into doc, I see automatic transform through babel is done for JS files.

@iambumblehead
Copy link
Owner

@maherma-adg https://jestjs.io/docs/ecmascript-modules try disabling transformations or configuring them to produce esm

@OlaoluwaM
Copy link

OlaoluwaM commented Feb 28, 2022

How can I set the loader for jest on esm?

@iambumblehead
Copy link
Owner

@OlaoluwaM if you make a PR with a sample basic jest test in it, I can try and make things work with that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants