mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Issue35876: Give better error message when Classic Module Resolution with incorrect path (#38105)
* added Error 5084 to diagnosticMessages.json * added test case errorForBareSpecifierWithImplicitModuleResolution1 to tests/cases/compiler * modified checker.ts to report error 5084 when classic resolution and incorrect path are used * added baseline changes * passes all test cases including src/testRunner/unittests/ tests * Update with feedback * Make it check whether it is the right module resolution kind * Use the right diagnostic message in tsserver tests Co-authored-by: Meera Shivakumar <mshivaku@umich.edu> Co-authored-by: Orta <git@orta.io>
This commit is contained in:
72 files changed
+290
-236
No files matched your search
@@ -2605,7 +2605,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier, dontResolveAlias = false): Symbol | undefined {
|
||||
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier!)!; // TODO: GH#18217
|
||||
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier!)!;
|
||||
const name = specifier.propertyName || specifier.name;
|
||||
const suppressInteropError = name.escapedText === InternalSymbolName.Default && !!(compilerOptions.allowSyntheticDefaultImports || compilerOptions.esModuleInterop);
|
||||
const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier!, dontResolveAlias, suppressInteropError);
|
||||
@@ -3112,9 +3112,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean): Symbol | undefined {
|
||||
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations);
|
||||
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
|
||||
const errorMessage = isClassic?
|
||||
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option
|
||||
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations;
|
||||
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage);
|
||||
}
|
||||
|
||||
function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage | undefined, isForAugmentation = false): Symbol | undefined {
|
||||
|
||||
@@ -3012,6 +3012,11 @@
|
||||
"category": "Error",
|
||||
"code": 2791
|
||||
},
|
||||
"Cannot find module '{0}'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?": {
|
||||
"category": "Error",
|
||||
"code": 2792
|
||||
},
|
||||
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
@@ -267,7 +267,7 @@ namespace ts.tscWatch {
|
||||
|
||||
export function getDiagnosticModuleNotFoundOfFile(program: Program, file: File, moduleName: string) {
|
||||
const quotedModuleName = `"${moduleName}"`;
|
||||
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, moduleName);
|
||||
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option, moduleName);
|
||||
}
|
||||
|
||||
export function runQueuedTimeoutCallbacks(sys: WatchedSystem) {
|
||||
|
||||
@@ -240,8 +240,8 @@ namespace ts.projectSystem {
|
||||
let diags = project.getLanguageService().getSemanticDiagnostics(root.path);
|
||||
assert.equal(diags.length, 1);
|
||||
const diag = diags[0];
|
||||
assert.equal(diag.code, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations.code);
|
||||
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar' or its corresponding type declarations.");
|
||||
assert.equal(diag.code, Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option.code);
|
||||
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?");
|
||||
callsTrackingHost.verifyCalledOn(CalledMapsWithSingleArg.fileExists, imported.path);
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user