-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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] MODULE_NOT_FOUND with typescript and node builtins. #2120
Comments
That's because it's possible for users to install their own version of the builtins so it's only allowed to resolve those. Otherwise TypeScript gets the types from |
Thanks, I did not know this is the case. I tried installing |
There is nothing to resolve, you just ignore them, it's how typescript finds types; they try a bunch of imports before falling back to |
Hi, thanks for the reply. Any advice how to ignore those? Our build logs and dev logs are flooded with those warnings. Would it make sense to add ENV variable or some flag to silence them, since they are not actionable? |
You can run Node with |
Thank you! However, it does not seem viable for us to "blanket ignore" all warnings generated by node. Would you be open to accept a PR with an ENV flag similar to |
I'd tend to say no ... I see the loose mode as a way to ease migrations - not something that should be used forever. In this context, allowing to hide the warnings would I think have a detrimental effect, as many users would just blindly ignore them, regardless how right they are. That being said, we sometimes bend the rules in special cases, and perhaps in this case we could automatically silence warnings for As a side note, if you really want this "ignore all" behavior, imo the right place for this would be in Node itself. Given that they provide the |
Has the problem been solved now?
|
Describe the bug
Typescript never seems to consider builtin modules for node, which causes a bunch of warnings like:
This seems to be the case in
loose
mode when there is another package which had declared dependency on the builtin module.To Reproduce
I did my best to create a minimal repro: https://github.com/JanMatas/yarn2-builtin-warning-repro.
Just:
yarn
yarn tsc --watch
I tried to dig through the yarn code and through the "typescript patch". It seems like it is hardcoded that builtins are never considered when doing pnp resolution (
considerBuiltins
:false
). The pnp resolution of builtins fails, buttsc
still somehow manages to compile the code (I did not dig deep enough to find out how - it must have some sort of fallback).Hence, the behaviour caused by this issues is limited to annoying warnings that appear if there is a fallback available on top level. The reproduction contains one of the modules (
@types/ioredis
) I found to emit warnings in our codebase (but there is many). I also added a random module that depends onevents
(aws-sdk
). From code, it seems that selection of modules for repro is arbitrary, as long as one tries to access builtin and the other declares a dependency on the builtin.I propose three solutions:
ALWAYS_WARN_ON_FALLBACKS
to work for top level fallbacks:berry/packages/yarnpkg-pnp/sources/loader/makeApi.ts
Line 636 in c8cba54
Happy to implement 1 and 3 and open a PR. Also happy to do 2, but I might need some guidance.
Environment if relevant (please complete the following information):
BTW, thanks a lot for awesome project. We just migrated to yarn2 and really enjoy the speedup of app loads and yarn installs and especially smaller node_modules!
The text was updated successfully, but these errors were encountered: