Always resolves to CJS even when using ESM
When using the usual ESM stuff, I still resolve to index.js instead of index.esm.js.
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
console.table({
"is-what": {
esm: import.meta.resolve("is-what"),
cjs: require.resolve("is-what"),
},
tosource: {
esm: import.meta.resolve("tosource"),
cjs: require.resolve("tosource"),
},
});
(Using is-what as an example of it done OK-ly)
I think this could be solved by using modern exports: {} conditions instead of main and module? But even this is not recommended so as to avoid the dual package hazard https://nodejs.org/api/packages.html#packages_dual_package_hazard where you can get two copies of the package code in your webpack/vite/rollup/parcel/whatever bundle.js file.
The idealized solution is to either a) only export an ESM version or b) export an ESM wrapper that just export {} from "./module.cjs" so that there's only one canonical source of code or c) only export a CJS version.
Funnily enough, in the package's current state it doesn't suffer from the dual package hazard since it currently only exports CommonJS 🤣
+1
Is there any news on this
I don't have any timeline for this (I haven't done any work on it). Definitely open to discussion/contribution.
Many of the drivers seem to have a setReadPreference method on the server connection, collection, and cursor objects. Is that what this is? Because setSlaveOk may not be sufficient for some use cases.