There is the isomorphic-webcrypto that pretends doing that but doesn't : it builds separate build for each target.
There is the noble-crypto way to do it, but it's based on if-else conditions and fails if I want an isomorphic mjs code.
Finally, there is the eval require way way to pass-through bundler, but node fails to use it in mjs.
In brief :
const crypto = require("crypto"); // work only in node.js but not in mjs file.
const crypto = eval(`require("crypto")`); // pass-thru bundler, then work only in node.js but not in mjs file.
window.crypto; // work only in browser
import * as crypto from "crypto"; // could work from both but must be at top level of a module, so it can't be a conditional import.
I would like to use native crypto in node.js and in browser, in an isomorphic way, to be able to use native import mjs in node and browser transparently.
How can I do this?