Skip to content
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

Add module and types to package.json to make it resolvable by TypeScript #303

Closed
wants to merge 1 commit into from

Conversation

emeryao
Copy link

@emeryao emeryao commented Oct 2, 2023

for now the package of change-case cannot be resolved by typescript with tsconfig "moduleResolution": "node" since the lack of module and types field in package.json

@emeryao
Copy link
Author

emeryao commented Oct 2, 2023

there is a kind of compatibility issue with the "moduleResolution": "node" in tsconfig.json and the exports field in package.json

if I change the moduleResolution to bundler or nodenext the package of change-case can be resolved as expected by TypeScript but updating tsconfig will break my entire project since all other packages will not be resolved as before

so by adding these two lines of code to package.json solves this issue

@blakeembrey
Copy link
Owner

blakeembrey commented Oct 2, 2023

The node module resolution isn’t compatible with ESM, you need to be using Node16, NodeNext, or Bundler. I won’t be merging this because it only happens to work today since this is a single file package. If I was ever to refactor this would break.

It’s an unfortunate situation for TypeScript but I’ll add some docs to the README instead. Node.js ESM isn’t compatible with any of the old module resolutions.

@blakeembrey blakeembrey closed this Oct 2, 2023
@blakeembrey
Copy link
Owner

blakeembrey commented Oct 2, 2023

but updating tsconfig will break my entire project since all other packages will not be resolved as before

Can you elaborate more on this? What broke? Are you currently using CommonJS or ESM or a bundler? Also, module in package.json isn’t a node feature, so I assume you’re specifically trying to make this work for a bundler and without changing the config to bundler?

Node16 adds ESM support to the existing Node resolution, it should not break anything that previously worked because Node16 still resolves the same thing you’re trying to add in this PR when the package is CommonJS.

@blakeembrey
Copy link
Owner

blakeembrey commented Oct 2, 2023

Here’s a similar report in TypeScript: microsoft/TypeScript#55104. It links to an issue in another repo that has a good explanation of the situation: typescript-eslint/typescript-eslint#7284

As TypeScript ESLint has done, I’m no longer supporting non-ESM versions of the package. To upgrade you will need to enable support for ESM, both in your environment (e.g. node, bun, etc) and TypeScript (with module resolution).

Being unable to upgrade is unfortunate, but I’m not forcing anyone to upgrade. The previous version has worked for years and will continue to work for as long as CommonJS is supported (hopefully forever).

@emeryao emeryao deleted the patch-1 branch October 3, 2023 06:10
@emeryao
Copy link
Author

emeryao commented Oct 3, 2023

fair enough 😃
my project is a angular@16 repo which defaults moduleresolution to node when i update it to bundler the import of @angular/commom/locales/en_US failed to be resolved

it's sure a issue of the @angular/common package and i will find a workaround

thanks for you kind replies 😃

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

Successfully merging this pull request may close these issues.

3 participants