Skip to content

Cannot use ".d.ts" file on non-relative import with rootDirs and baseUrlΒ #54749

Open

Description

Bug Report

πŸ”Ž Search Terms

baseUrl rootDirs non-relative module .d.ts

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried : 5.1.3 and 4.9.5.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "./src",
    "rootDirs": [".", "generated"],
  }
}
// src/index.ts
import stylesA from "css/a.module.scss" // πŸ‘Ž Cannot find module 'css/a.module.scss' or its corresponding type declarations.ts(2307)
import stylesB from "./css/b.module.scss" // πŸ‘

console.log(stylesA, stylesB)
// src/css/a.module.scss
.a {
    color: red;
}

// src/css/b.module.scss
.b {
    color: red;
}
// generated/src/css/a.module.scss.d.ts
export type Styles = {
  'a': string;
};

declare const styles: Styles;

export default styles;

// generated/src/css/b.module.scss.d.ts
export type Styles = {
  'b': string;
};

declare const styles: Styles;

export default styles;

πŸ™ Actual behavior

On first import in index.ts, the ".d.ts" file is not found: "Cannot find module 'css/a.module.scss' or its corresponding type declarations.ts(2307)"
On the second one, the ".d.ts" file is found and types are displayed correctly.

πŸ™‚ Expected behavior

Whenever it's a non-relative import (thanks to the baseUrl option) or a relative import, it should find the ".d.ts" file because of the rootDirs settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions