Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
var noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
var useUnknownInCatchVariables = getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
var exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;
var noUncheckedSideEffectImports = !!compilerOptions.noUncheckedSideEffectImports;
var noUncheckedSideEffectImports = compilerOptions.noUncheckedSideEffectImports !== false;

var checkBinaryExpression = createCheckBinaryExpression();
var emitResolver = createResolver();
Expand Down Expand Up @@ -4684,9 +4684,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}

function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean): Symbol | undefined {
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean, errorMessage?: DiagnosticMessage): Symbol | undefined {
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
const errorMessage = isClassic ?
errorMessage ??= isClassic ?
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_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, ignoreErrors);
Expand Down Expand Up @@ -48516,7 +48516,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
else if (noUncheckedSideEffectImports && !importClause) {
void resolveExternalModuleName(node, node.moduleSpecifier);
void resolveExternalModuleName(node, node.moduleSpecifier, /*ignoreErrors*/ undefined, Diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0);
}
}
checkImportAttributes(node);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
affectsBuildInfo: true,
category: Diagnostics.Modules,
description: Diagnostics.Check_side_effect_imports,
defaultValueDescription: false,
defaultValueDescription: true,
},

// Source Maps
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4007,6 +4007,10 @@
"category": "Error",
"code": 2881
},
"Cannot find module or type declarations for side-effect import of '{0}'.": {
"category": "Error",
"code": 2882
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
10 changes: 8 additions & 2 deletions tests/baselines/reference/amdDependencyCommentName4.errors.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
amdDependencyCommentName4.ts(6,8): error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule1'.
amdDependencyCommentName4.ts(8,21): error TS2792: Cannot find module 'aliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
amdDependencyCommentName4.ts(11,26): error TS2792: Cannot find module 'aliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
amdDependencyCommentName4.ts(14,15): error TS2792: Cannot find module 'aliasedModule3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
amdDependencyCommentName4.ts(17,21): error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
amdDependencyCommentName4.ts(20,8): error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule2'.


==== amdDependencyCommentName4.ts (4 errors) ====
==== amdDependencyCommentName4.ts (6 errors) ====
///<amd-dependency path='aliasedModule5' name='n1'/>
///<amd-dependency path='unaliasedModule3'/>
///<amd-dependency path='aliasedModule6' name='n2'/>
///<amd-dependency path='unaliasedModule4'/>

import "unaliasedModule1";
~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule1'.

import r1 = require("aliasedModule1");
~~~~~~~~~~~~~~~~
Expand All @@ -32,4 +36,6 @@ amdDependencyCommentName4.ts(17,21): error TS2792: Cannot find module 'aliasedMo
!!! error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
ns;

import "unaliasedModule2";
import "unaliasedModule2";
~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule2'.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can
autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(34,17): error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(35,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(37,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can only appear on a property declaration.


==== autoAccessorDisallowedModifiers.ts (30 errors) ====
==== autoAccessorDisallowedModifiers.ts (31 errors) ====
abstract class C1 {
accessor accessor a: any;
~~~~~~~~
Expand Down Expand Up @@ -115,6 +116,8 @@ autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can
accessor import "x";
~~~~~~~~
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.
~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
accessor import {} from "x";
~~~~~~~~
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can
autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(34,17): error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(35,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(37,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can only appear on a property declaration.


==== autoAccessorDisallowedModifiers.ts (30 errors) ====
==== autoAccessorDisallowedModifiers.ts (31 errors) ====
abstract class C1 {
accessor accessor a: any;
~~~~~~~~
Expand Down Expand Up @@ -115,6 +116,8 @@ autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can
accessor import "x";
~~~~~~~~
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.
~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
accessor import {} from "x";
~~~~~~~~
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
validator.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of './'.
validator.ts(19,4): error TS2540: Cannot assign to 'readonlyProp' because it is a read-only property.
validator.ts(20,4): error TS2540: Cannot assign to 'readonlyAccessor' because it is a read-only property.
validator.ts(21,1): error TS2322: Type 'string' is not assignable to type 'number'.
validator.ts(22,1): error TS2322: Type 'string' is not assignable to type 'number'.
validator.ts(23,1): error TS2322: Type 'number' is not assignable to type 'string'.


==== validator.ts (5 errors) ====
==== validator.ts (6 errors) ====
import "./";
~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './'.

import Person = require("./mod1");

Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/emit(jsx=preserve).errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ main.ts(3,16): error TS2307: Cannot find module '../foo.mts' or its correspondin
main.ts(4,16): error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations.
main.ts(5,16): error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations.
main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
main.ts(7,8): error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
Expand All @@ -23,7 +24,7 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
==== globals.d.ts (0 errors) ====
declare function require(module: string): any;

==== main.ts (10 errors) ====
==== main.ts (11 errors) ====
// Rewrite
import {} from "./foo.ts";
~~~~~~~~~~
Expand All @@ -41,6 +42,8 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
~~~~~~~~~~
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
import "./foo.ts";
~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
export * from "./foo.ts";
~~~~~~~~~~
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/emit(jsx=react).errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ main.ts(3,16): error TS2307: Cannot find module '../foo.mts' or its correspondin
main.ts(4,16): error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations.
main.ts(5,16): error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations.
main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
main.ts(7,8): error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
Expand All @@ -23,7 +24,7 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
==== globals.d.ts (0 errors) ====
declare function require(module: string): any;

==== main.ts (10 errors) ====
==== main.ts (11 errors) ====
// Rewrite
import {} from "./foo.ts";
~~~~~~~~~~
Expand All @@ -41,6 +42,8 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
~~~~~~~~~~
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
import "./foo.ts";
~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
export * from "./foo.ts";
~~~~~~~~~~
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
es6ImportWithoutFromClauseInEs5_1.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseInEs5_0'.


==== es6ImportWithoutFromClauseInEs5_0.ts (0 errors) ====
export var a = 10;

==== es6ImportWithoutFromClauseInEs5_1.ts (1 errors) ====
import "es6ImportWithoutFromClauseInEs5_0";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseInEs5_0'.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
client.ts(1,1): error TS1191: An import declaration cannot have modifiers.
client.ts(1,15): error TS2882: Cannot find module or type declarations for side-effect import of 'server'.


==== server.ts (0 errors) ====
export var a = 10;

==== client.ts (1 errors) ====
==== client.ts (2 errors) ====
export import "server";
~~~~~~
!!! error TS1191: An import declaration cannot have modifiers.
!!! error TS1191: An import declaration cannot have modifiers.
~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'server'.
20 changes: 20 additions & 0 deletions tests/baselines/reference/extendGlobalThis.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
index.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of './extention'.


==== extension.d.ts (0 errors) ====
declare global {
namespace globalThis {
var test: string;
}
}

export {}

==== index.ts (1 errors) ====
import "./extention";
~~~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './extention'.

globalThis.tests = "a-b";
console.log(globalThis.test.split("-"));

1 change: 1 addition & 0 deletions tests/baselines/reference/extendGlobalThis.types
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ globalThis.tests = "a-b";
>globalThis.tests = "a-b" : "a-b"
> : ^^^^^
>globalThis.tests : any
> : ^^^
>globalThis : typeof globalThis
> : ^^^^^^^^^^^^^^^^^
>tests : any
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
index.tsx(1,8): error TS2882: Cannot find module or type declarations for side-effect import of './jsx'.


==== index.tsx (1 errors) ====
import "./jsx";
~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './jsx'.

var skate: any;
const React = { createElement: skate.h };

class Component {
renderCallback() {
return <div>test</div>;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import "./jsx";

var skate: any;
>skate : any
> : ^^^

const React = { createElement: skate.h };
>React : { createElement: any; }
> : ^^^^^^^^^^^^^^^^^^^^^^^
>{ createElement: skate.h } : { createElement: any; }
> : ^^^^^^^^^^^^^^^^^^^^^^^
>createElement : any
> : ^^^
>skate.h : any
> : ^^^
>skate : any
> : ^^^
>h : any
Expand All @@ -27,7 +30,8 @@ class Component {
> : ^^^^^^^^^

return <div>test</div>;
><div>test</div> : error
><div>test</div> : any
> : ^^^
>div : any
> : ^^^
>div : any
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
jsxImportForSideEffectsNonExtantNoError.tsx(4,8): error TS2882: Cannot find module or type declarations for side-effect import of './App.css'.


==== jsxImportForSideEffectsNonExtantNoError.tsx (1 errors) ====
/// <reference path="/.lib/react16.d.ts" />
import * as React from "react";

import "./App.css"; // doesn't actually exist
~~~~~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of './App.css'.

const tag = <div></div>;

27 changes: 27 additions & 0 deletions tests/baselines/reference/moduleAugmentationInAmbientModule5.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,30 @@ var y = x.getA().x;

//// [f.d.ts]
import "array";


//// [DtsFileErrors]


f.d.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'array'.


==== f.d.ts (1 errors) ====
import "array";
~~~~~~~
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'array'.

==== array.d.ts (0 errors) ====
declare module "A" {
class A { x: number; }
}

declare module "array" {
import {A} from "A";
global {
interface Array<T> {
getA(): A;
}
}
}

Loading
Loading