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

Friendly note on unexpected side-effects of 2.1.5->2.1.6 transition #21

Closed
ukstv opened this issue Jul 15, 2021 · 5 comments · Fixed by mikeal/ipjs#14
Closed

Friendly note on unexpected side-effects of 2.1.5->2.1.6 transition #21

ukstv opened this issue Jul 15, 2021 · 5 comments · Fixed by mikeal/ipjs#14

Comments

@ukstv
Copy link
Contributor

ukstv commented Jul 15, 2021

Using marvellous uint8arrays library extensively. The recent change depends on multiformats module instead of previous multibase. Apparently, multiformats uses conditional exports in its package.json, and vanilla Jest can not handle those.

So, if some people start complaining on their tests failing with cryptic errors, like Cannot read property 'base16' of undefined, please know, this is due to Jest unable to load multiformats properly.

A solution I have for the downstream users is to use custom resolver for Jest (jest-resolver-enhanced), like in the following fragment of package.json:

{
  "jest": {
    "resolver": "jest-resolver-enhanced"
  },
}

Any other resolver capable of handling conditional exports is just as fine, but every one I know of, are unusable right now due to old age. Checked them all, IMO.

achingbrain added a commit to achingbrain/ipjs that referenced this issue Jul 15, 2021
Jest [doesn't support package exports](jestjs/jest#9771),
nor does it support `browser` overrides out of the box (though it
[can be configured](https://jestjs.io/docs/configuration#resolver-string)).

This means it parses the stubbed files introduced in mikeal#13 as javascript,
so let's just require and export the file that the stub is stubbing.

This has the added bonus of also supporting old nodes that don't
understand package exports.

Fixes achingbrain/uint8arrays#21
@achingbrain
Copy link
Owner

Ah, that's annoying, sorry about that.

I've just opened mikeal/ipjs#14 which when building multiformats with the changes in that PR means it works with jest for me locally. I'll get a multiformats release out as soon as it's merged.

In the mean time please use your custom resolver or pin uint8arrays to 2.1.5.

mikeal pushed a commit to mikeal/ipjs that referenced this issue Jul 15, 2021
Jest [doesn't support package exports](jestjs/jest#9771),
nor does it support `browser` overrides out of the box (though it
[can be configured](https://jestjs.io/docs/configuration#resolver-string)).

This means it parses the stubbed files introduced in #13 as javascript,
so let's just require and export the file that the stub is stubbing.

This has the added bonus of also supporting old nodes that don't
understand package exports.

Fixes achingbrain/uint8arrays#21
@achingbrain
Copy link
Owner

achingbrain commented Jul 15, 2021

This should be fixed in multiformats@9.4.2. I've published uint8arrays@2.1.7 which sets this as the minimum version of multiformats required.

Please let me know if this still causes you problems.

@achingbrain
Copy link
Owner

Closing this as it should be fixed, please re-open if you continue to see problems.

@ukstv
Copy link
Contributor Author

ukstv commented Jul 17, 2021

Thanks @achingbrain

vasco-santos pushed a commit to vasco-santos/ipjs that referenced this issue Jul 29, 2021
Jest [doesn't support package exports](jestjs/jest#9771),
nor does it support `browser` overrides out of the box (though it
[can be configured](https://jestjs.io/docs/configuration#resolver-string)).

This means it parses the stubbed files introduced in mikeal#13 as javascript,
so let's just require and export the file that the stub is stubbing.

This has the added bonus of also supporting old nodes that don't
understand package exports.

Fixes achingbrain/uint8arrays#21
@alexeygorbachevsky
Copy link

@achingbrain It seems the issue is being reproduced for now. I had the error "Cannot read property 'base16' of undefined" and fixed it only via resolver as was suggested above ->
{
"jest": {
"resolver": "jest-resolver-enhanced"
},
}

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.

3 participants