-
-
Notifications
You must be signed in to change notification settings - Fork 75
[css-tokenizer] add types entry in package.json for older projects #1437
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
Conversation
namely where `compilerOptions.moduleResolution < "node16"` in tsconfig.json
This is not about commonjs, it's more about compatibility. Merely including this field does not support commonjs, but gives bundlers and typescript more options to find the type definitions if there are other configuration constraints that prevent reading from the Edit: I apologize if this has already been thoroughly discussed elsewhere, but it seems to me that it is intentionally breaking compatibility unnecessarily. |
Commonjs is supported. If you get a warning about types, they you are actually generating commonjs. We can't generate types that are correct for both esm and cjs. So this is not a compat issue, commonjs works. You just don't get types, which is not blocking, you can silence the warning about the types. We also have API docs to aid you in using these packages. |
You're right, I did not fully understand the situation and I apologize. However, I would like to add my data point. For reference, my project does not use commonjs, but generates esm bundles with what I suppose is commonjs configurations in both my package.json and tsconfig.json. I could be using it completely wrong, but I believe this setup was rather common near the introduction of esm in nodejs. The bundler automatically includes the esm source if available and falls back to cjs with a wrapper. We have not run into any commonjs issues related to type definitions using this setup. I was able to rollback to v2.2.1 for the type definitions. |
🤔 If your project really is using and generating esm, then you should have working types. Or even better submit a PR with a minimal repro? We have some e2e tests to ensure that TypeScript works, for example this one : https://github.com/csstools/postcss-plugins/tree/main/e2e/typescript/esm So either your project isn't generating esm, which really is easy to do by accident, or we do have a bug somewhere. |
There is actually no problem with the bundling. My deployment environment does not support commonjs, so the generated bundle is definitely esm. The only problem is the tooling. Because my moduleResolution is not node16, typescript doesn't read the exports and the type checking fails. I'm fairly certain this is an artifact of the bare minimum effort to make a pre-esm project to target an esm environment. I don't think I'll have time to build a minimal repro, but here is my tsconfig:
I have also tried using node16 module resolution, but that breaks more packages than it fixes. |
Do you have |
Nope, and that's exactly the problem. I tried renaming the file to |
https://www.typescriptlang.org/tsconfig/#moduleResolution
So you are still effectively using commonjs, which we don't have types for :) So this definitely is an issue with your config. |
namely where
compilerOptions.moduleResolution < "node16"
in tsconfig.json