Skip to content

Export "types" for "require" too #1572

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

Closed
asamuzaK opened this issue Feb 22, 2025 · 5 comments
Closed

Export "types" for "require" too #1572

asamuzaK opened this issue Feb 22, 2025 · 5 comments

Comments

@asamuzaK
Copy link

For example, in @csstools/css-calc package.json
It lacks "types" for cjs.

"exports": {
		".": {
			"import": {
				"types": "./dist/index.d.ts",
				"default": "./dist/index.mjs"
			},
			"require": {
				"default": "./dist/index.cjs"
			}
		}
	},

It causes error TS7016: Could not find a declaration file for module '@csstools/css-calc' when building with vite.
See: https://github.com/asamuzaK/cssColor/actions/runs/13327572771/job/37224110621#step:5:112

@lachlancollins
Copy link

lachlancollins commented Feb 22, 2025

More information here: https://publint.dev/rules#types_not_exported

Issue on Publint repo: publint/publint#160

@lachlancollins
Copy link

lachlancollins commented Feb 22, 2025

That is not a bug. We do not support types for commonjs.

Hi @romainmenke , thanks for the reply, I didn't know there was a long context to this! ESM/CJS type resolution is a very complex and finicky issue I am well aware of.

I can see that tools like unbuild and tshy have been suggested before. The TanStack team now use our own tool, which is effectively just a shared Vite config which solves all of these problems we've encountered.

If you're open to it, I'd be happy to submit a draft PR to show what this would look like for this repo?

@romainmenke
Copy link
Member

romainmenke commented Feb 22, 2025

No we are not going to change our setup or built system.
In the (distant) future we will completely remove support for commonjs and move to pure es modules.

With support for es module imports from commonjs picking up this is the better way forward.

You can silence errors with things like @ts-expect-error

@romainmenke romainmenke closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2025
@lachlancollins
Copy link

With support for es module imports from commonjs picking up this is the better way forward.

Absolutely! Glad to hear :)

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

No branches or pull requests

3 participants