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

🐛 Bug: Cannot be used directly from node due to module setup #277

Closed
3 tasks done
phryneas opened this issue Sep 7, 2023 · 3 comments
Closed
3 tasks done

🐛 Bug: Cannot be used directly from node due to module setup #277

phryneas opened this issue Sep 7, 2023 · 3 comments
Labels
invalid This doesn't seem right

Comments

@phryneas
Copy link

phryneas commented Sep 7, 2023

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

Importing this module from a .mjs file should work

Actual

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/tronic/tmp/apollo-client/node_modules/ts-api-tools/lib/tokens' imported from /Users/tronic/tmp/apollo-client/node_modules/ts-api-tools/lib/comments.js

Additional Info

The import statements in the lib folder would require a .js extension for this to work.

Here's a pretty minimal reproduction:

https://github.com/apollographql/apollo-client/tree/65e31716c7f363158309e990946f73e410c73837/config/eslint-rules

(Run npm run test in the config/eslint-rules folder)

Also visible here: If you rename these files to .js to use CommonJS require, TypeScript complains:
image

Those complaints only go away after removing the type: "module" from this module's package.json - it seems that TypeScript ignores the require exports conditions once type: "module" is present.

@phryneas phryneas added the type: bug Something isn't working :( 🐛 label Sep 7, 2023
@JoshuaKGoldberg
Copy link
Owner

ts-api-tools

The package is ts-api- utils now 😄. I'd originally called it tools then realized utils makes more sense as a name (#27).

I tried swapping them out locally and it all worked.

It is unfortunate how realistic-looking the old npm package is. I ran npm deprecate ts-api-tools "Renamed to ts-api-utils" just now to help with that.

Cheers, and thanks for using! ❤️‍🔥

@JoshuaKGoldberg JoshuaKGoldberg added invalid This doesn't seem right and removed type: bug Something isn't working :( 🐛 labels Sep 7, 2023
@phryneas
Copy link
Author

phryneas commented Sep 7, 2023

Dang! That one is still mentioned in the Eslint docs, here: https://typescript-eslint.io/developers/custom-rules/#typed-rules

image

A miractle you get so few downloads on the wrong ones in that light ^^

Thanks for looking into it!

@JoshuaKGoldberg
Copy link
Owner

JoshuaKGoldberg commented Sep 7, 2023

A miracle you get so few downloads on the wrong ones in that light ^^

That's one way of looking at it. Another would be that almost nobody reads the docs 🫠🫠🫠

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants