mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge pull request #25949 from Microsoft/resolveJsonModuleError
When json module is not found, include enabling --resolveJsonModule might help.
This commit is contained in:
commit
2b14bcbb56
@ -2220,6 +2220,12 @@ namespace ts {
|
||||
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
|
||||
error(errorNode, diag, tsExtension, removeExtension(moduleReference, tsExtension));
|
||||
}
|
||||
else if (!compilerOptions.resolveJsonModule &&
|
||||
fileExtensionIs(moduleReference, Extension.Json) &&
|
||||
getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeJs &&
|
||||
getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS) {
|
||||
error(errorNode, Diagnostics.Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension, moduleReference);
|
||||
}
|
||||
else {
|
||||
error(errorNode, moduleNotFoundError, moduleReference);
|
||||
}
|
||||
|
||||
@ -2425,6 +2425,10 @@
|
||||
"category": "Error",
|
||||
"code": 2731
|
||||
},
|
||||
"Cannot find module '{0}'. Consider using '--resolveJsonModule' to import module with '.json' extension": {
|
||||
"category": "Error",
|
||||
"code": 2732
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
tests/cases/compiler/file1.ts(1,21): error TS2307: Cannot find module './b.json'.
|
||||
tests/cases/compiler/file1.ts(3,21): error TS2307: Cannot find module './b.json'.
|
||||
tests/cases/compiler/file1.ts(1,21): error TS2732: Cannot find module './b.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
|
||||
tests/cases/compiler/file1.ts(3,21): error TS2732: Cannot find module './b.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.ts (2 errors) ====
|
||||
import b1 = require('./b.json'); // error
|
||||
~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find module './b.json'.
|
||||
!!! error TS2732: Cannot find module './b.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
|
||||
let x = b1.a;
|
||||
import b2 = require('./b.json'); // error
|
||||
~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find module './b.json'.
|
||||
!!! error TS2732: Cannot find module './b.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
|
||||
if (x) {
|
||||
let b = b2.b;
|
||||
x = (b1.b === b);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user