-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Give better error messages for bare imports with badly configured projects #35876
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
Comments
I want to add here, that the Playground does not even allow to set a I tried reproducing some errors and was confused about why am I getting different outcomes in the playground compared to my actual code. Only after fiddling with it CodeSandbox I eventually found out that I was not able to find if Playground issues should be reported somewhere else. Should I open a separate issue here? Why is the classic resolution still being kept as default for a new module types? |
Yes, https://github.com/Microsoft/TypeScript-Website, though I would say the website should probably just always display
Yeah, there's #11434 but I don't think we ever got around to the work. |
The playground side of this is done (it always defaults to Which leaves the warning on imports to do 👍 |
Can me and @nityatammana work on this? |
Sure - you might want to create one new diagnostic in
Run Run the tests
see what breaks. Diff the folders If nothing fails, you need to add a test case in a file named // @module: es2015
import { thing } from "non-existent-module";
thing() Then run the tests to get baselines from that. Accept the baselines:
|
Hi again! To check in we've added the diagnostic and ran We're confused as to how to populate the local folder beyond running the tests locally. Also, to clarify, in addition to adding to |
The local folder only changes when the baselines have changed - so if your diffs don't match the reference folder. Adding the throw in the user's project (e.g. creating the error diagnostic) should be the thing which will break a reference test of two hopefully. |
Let's steer away from the word "throw" because that's just not the way TypeScript reports errors. You need to report the diagnostic/error that I mentioned in my last comment instead of the current error when the project is misconfigured. |
Me and @nityatammana think we've found a fix, but after accepting the baselines, 10 tests fail that don't include tests we've modified baselines for and don't appear in the tests/baselines/local folder after failing. I've attached images of the first 3 below. If anyone has any insights, I would be very happy to hear it! |
You need to edit the error on |
If the default isn't changed to 'node' everywhere (to maintain backwards compatibility) - could a warning just be emitted whenever 'moduleResolution' defaults to classic (rather than just when an import fails). Something like "warning: moduleResolution defaulting to classic due to your module setting, which is probably not what you want." If the moduleResolution is explicitly set to classic (either in tsconfig or cmd line) then that would silence the warning. I'd personally favour just changing the default, but as it would be a behaviour change for existing projects then I understand why it might not have happened yet. |
Thanks for the PR @mshivaku99, and thank you @orta for helping guide the PR! |
(and @sheetalkamat for the guidance above!) |
I ran into this issue also. Why isn't "node" the default module resolution strategy? |
How do I fix the issue? I'm running into the same issue in my project. Thanks! |
@saramorsi , I just added this line under
|
When targeting
es2015
or later,moduleResolution
isn't set tonode
by default.Perhaps when
moduleResolution
is calculated to beclassic
andpaths
aren't specifiedwe should hint to the user
The text was updated successfully, but these errors were encountered: