Skip to content

fix exports in package.json to work with ts's implementation of node16 moduleResolution #549

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

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/device-id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved main and types together because logically that's how it works. Systems that import code will use those if they aren't using exports.

Comment on lines 25 to +26
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all the consumers of these packages updated? In which case we could keep things simple and just delete the "main" and "types", as per Node.js docs:

The "exports" provides a modern alternative to "main" allowing multiple entry points to be defined, conditional entry resolution support between environments, and preventing any other entry points besides those defined in "exports". This encapsulation allows module authors to clearly define the public interface for their package.

For new packages targeting the currently supported versions of Node.js, the "exports" field is recommended. For packages supporting Node.js 10 and below, the "main" field is required. If both "exports" and "main" are defined, the "exports" field takes precedence over "main" in supported versions of Node.js.

Suggested change
"main": "dist/index.js",
"types": "./dist/index.d.ts",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking about that. I don't know if I can tell 100% before just removing these. And if it doesn't "just work" I'd have to upgrade all our repos at once. I was thinking I can remove those in a separate PR and then if it all blows up I only have to revert that one PR.

"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
Copy link
Collaborator Author

@lerouxb lerouxb Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anything that's going to use exports.require is actually going to pick up this types field because the commonjs moduleResolution in typescript was clearly happily using "types" from the root and now with node16 it will use import.types. plus node/js (outside of typescript) is never going to import the types anyway but it is here for consistency.

Copy link
Collaborator

@kraenhansen kraenhansen Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "types" condition like this is redundant, since TSC will automatically infer it from the .js file.

Suggested change
"types": "./dist/index.d.ts"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "types" condition like this is redundant, since TSC will automatically infer it from the .js file.

is this the case? I have had issues with packages which don't explicitly define it before

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that'd work if you do "require": "./dist/index.js",
but not "require": {default: "./dist/index.js",}?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this because if someone does use the commonjs module resolution method (or something in between) it would work if it picks both main and types from the root, but what if it picks exports.require? We'd basically rely on it falling back to the types field at the root? I don't think we want types inferred if there are proper types, do we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait I think I'm misunderstanding. You mean the top-level one since ts will be using the exports anyway? I suspect you're right.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted with @lerouxb offline, I'd be happy to share an example for anyone interested.

},
Comment on lines +29 to +32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "types" condition like this is redundant, since TSC will automatically infer it from the .js file.

Suggested change
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"require": "./dist/index.js",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so just for the "require" ones? I left a comment elsewhere where I already had a suspicion like that.

"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
Copy link
Collaborator Author

@lerouxb lerouxb Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment here says that you need separate types files for require/import but so far in my testing by just npm linking things together it seems to work?

What I'll do once this PR lands is to make sure we bump all these packages where they are used so that I find and fix any errors and not someone else.

If we do need a types files in a different format, then I guess we'll have to change https://github.com/addaleax/gen-esm-wrapper

}
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
24 changes: 17 additions & 7 deletions packages/devtools-proxy-support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,29 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"./proxy-options": {
"require": "./dist/proxy-options-public.js",
"import": "./dist/.esm-wrapper-po.mjs",
"types": "./dist/proxy-options-public.d.ts"
"require": {
"default": "./dist/proxy-options-public.js",
"types": "./dist/proxy-options-public.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper-po.mjs",
"types": "./dist/proxy-options-public.d.ts"
}
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/dl-center/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"generate-config-from-schema": "json2ts -i src/download-center-config.schema.json -o src/download-center-config.ts --bannerComment \"/* AUTO-GENERATED DO NOT EDIT. */\"",
"pretest": "npm run generate-config-from-schema && npm run reformat",
Expand Down
13 changes: 9 additions & 4 deletions packages/download-url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
"reformat": "npm run prettier -- --write ."
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"exports": {
"require": "./lib/index.js",
"import": "./.esm-wrapper.mjs",
"types": "./lib/index.d.ts"
"require": {
"default": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"import": {
"default": "./.esm-wrapper.mjs",
"types": "./lib/index.d.ts"
}
},
"typings": "lib/index.d.ts",
"bin": {
"mongodb-download-url": "bin/mongodb-download-url.js"
},
Expand Down
11 changes: 8 additions & 3 deletions packages/get-os-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
"license": "Apache-2.0",
"main": "dist/index.js",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
Expand Down
13 changes: 9 additions & 4 deletions packages/mongodb-cloud-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/mongodb-constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/mongodb-downloader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/mongodb-redact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
11 changes: 7 additions & 4 deletions packages/mongodb-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
},
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/mongodb-ts-autocomplete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
12 changes: 11 additions & 1 deletion packages/mql-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@
},
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"./schema": {
"types": "./out/schema.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
9 changes: 6 additions & 3 deletions packages/native-machine-id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
},
"license": "Apache-2.0",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
Expand Down
13 changes: 9 additions & 4 deletions packages/oidc-http-server-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/oidc-mock-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
},
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/query-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
13 changes: 9 additions & 4 deletions packages/sbom-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
],
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
"require": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"import": {
"default": "./dist/.esm-wrapper.mjs",
"types": "./dist/index.d.ts"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"bootstrap": "npm run compile",
"prepublishOnly": "npm run compile",
Expand Down
Loading