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

fix(check): move module not found errors to typescript diagnostics #27533

Merged
merged 6 commits into from
Jan 3, 2025

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Jan 3, 2025

Instead of hard erroring, we now surface module not found errors as TypeScript diagnostics (we have yet to show the source code of the error, but something we can improve over time).

> deno check main.ts
error: Module not found "file:///V:/scratch/other1.js".
    at file:///V:/scratch/main.ts:1:23
V:\scratch
> ../deno/target/debug/deno check main.ts
Check file:///V:/scratch/main.ts
error: TS2307 [ERROR]: Cannot find module 'file:///V:/scratch/other1.js'.
    at file:///V:/scratch/main.ts:1:23

TS2307 [ERROR]: Cannot find module 'file:///V:/scratch/other2.js'.
    at file:///V:/scratch/main.ts:2:23

Found 2 errors.
> npx tsc
main.ts:1:23 - error TS2307: Cannot find module './other1.js' or its corresponding type declarations.

1 import { TestA } from "./other1.js";
                        ~~~~~~~~~~~~~

main.ts:2:23 - error TS2307: Cannot find module './other2.js' or its corresponding type declarations.

2 import { TestB } from "./other2.js";
                        ~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: main.ts:1

This doesn't work yet for npm modules, but it's what I'll work on next.

Closes #27188

@dsherret dsherret marked this pull request as draft January 3, 2025 01:15
@dsherret

This comment was marked as outdated.

@dsherret dsherret marked this pull request as ready for review January 3, 2025 19:14
}

/// Gets a hash of the inputs for type checking. This can then
/// be used to tell
fn get_check_hash(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this into get_tsc_roots is more reliable because then the code is the same. There were some slight discrepancies before.

.as_ref()
.and_then(|d| d.dependency.ok());
} else if let Module::Wasm(module) = module {
maybe_module_dependencies = Some(&module.dependencies);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug here where we weren't visiting wasm module dependencies.


if let Some(range) = error.maybe_range() {
if mode == EnhanceGraphErrorMode::ShowRange
&& !range.specifier.as_str().contains("/$deno$eval")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch 😬 not super important, but maybe we should list out these "magical" specifiers in consts in a single module and use these consts instead of string literals?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was already here so I'll leave it as-is for now.

Comment on lines +402 to +403
// todo(dsherret): it looks like the remapped_specifiers and
// root_map could be combined... what is the point of the separation?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely no point, just a legacy code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will update it in a follow-up pr.

cli/tsc/mod.rs Outdated Show resolved Hide resolved
@dsherret dsherret enabled auto-merge (squash) January 3, 2025 21:12
Copy link
Collaborator

@nayeemrmn nayeemrmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dsherret dsherret merged commit 89c92b8 into denoland:main Jan 3, 2025
17 checks passed
@dsherret dsherret deleted the fix_module_not_found_ts_diagnostic branch January 4, 2025 00:25
dsherret added a commit that referenced this pull request Jan 9, 2025
…27533)

Instead of hard erroring, we now surface module not found errors as
TypeScript diagnostics (we have yet to show the source code of the
error, but something we can improve over time).
@invalidred
Copy link

TYSM @dsherret for fixing this issue! Ya'll rock.

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.

Surface not found modules as diagnostics instead of erroring and failing to load
4 participants