Closed Robin-Hoodie closed 2 years ago
This is a jest configuration issue.
Both this package and uint8array-tools are set to use require
for node environments and import
for browser environments.
Most likely setting your jest environment to node should fix the issue.
Jest ESM support is a separate issue. Right now it's bundling the MJS code as a CJS.
Or maybe it's a babel issue. Assuming you followed that website directions exactly.
I work on a private project that uses ts-jest instead of babel and everything works fine, btw.
I've tried running files through the ts-jest
transformer now, with the same result.
Let me see if I can create a repro for this
@junderw Here's a repro https://github.com/Robin-hoodie/tiny-secp256k1-repro
I am having the same issue
This issue is not with this library. We have used the official NodeJS methods for providing cjs backwards compatibility.
Please follow the issue on the jest repository.
https://github.com/facebook/jest/issues/9771#issuecomment-776681032
Try using a custom resolver.
looks like babel also has the same issue.
Thanks for the input @junderw , I've been able to "resolve" (pun intended) this now
For anyone experiencing the same problem, here's the TLDR:
Jest currently does not support the package.json#exports
field (see https://github.com/facebook/jest/issues/9771). Currently Jest plans to add support for it in v28. In case v28 has been released when you're reading this, I'd try just upgrading Jest and see if that resolves the issue.
If v28 has not been released yet or v28 also does not resolve this issue, you can use the suggestion mentioned here I've implemented this as follows:
// jest.config.js
module.exports = {
resolver: "<rootDir>/jest-resolver.js"
// any other options go here
}
// ./jest-resolver.js
const enhancedResolve = require("enhanced-resolve");
const resolver = enhancedResolve.create.sync({
conditionNames: ["require", "node", "default", "import"],
extensions: [".js", ".json", ".node", ".ts"],
});
module.exports = (request, options) => resolver(options.basedir, request);
@junderw As I understood, adding a package.json#main
field would also resolve the issue. Is there a specific reason this has not been added? If you just haven't gotten around to it, let me know and I can create a PR for it.
"tiny-secp256k1"
jest
This results in the following error
It seems the
compare
import from"uint8array-tools"
is the culprit hereDowngrading to version
1.1.6
resolves the issueHappy to create a repro or help out if necessary