Skip to content

"Cannot find module" when using project references #36708

@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 3.7.5, 3.8.1-rc

Note: this was originally posted to microsoft/vscode#80423. I was told there that #30823 would fix this.

#30823 was apparently fixed by #33287, however this issue still remains.


Steps to Reproduce:

./tsconfig-src.json:

{
    "compilerOptions": {
        "composite": true,
        "declarationMap": true,
        "outDir": "./target/",
        "baseUrl": "./src/"
    },
    "include": ["./src/**/*"]
}

./tsconfig.json:

{
    "references": [{ "path": "./tsconfig-src.json" }],
    "files": []
}

./src/main.ts:

import { foo } from 'helpers/functions';

foo;

./src/helpers/functions.ts:

export const foo = 1;

When I run tsc --build, it builds with no errors.

When I navigate to a TS file in VS Code, e.g. ./src/main.ts, I get errors: Cannot find module 'helpers/functions'

I expected this to work because VS Code would find the ./tsconfig.json in the parent/root directory, and this references ./tsconfig-src.json (the TS project which includes the file I'm looking at: ./src/main.ts).

Repo including the above test case: https://github.com/OliverJAsh/unsplash-ts-project-references

I understand I could workaround this by moving ./tsconfig-src.json into the ./src/ folder at ./src/tsconfig.json, but I believe that shouldn't be necessary.

What's more, in my real world application the ./tsconfig-src.json includes files in multiple root folders (./src/, ./client/, ./server/), not just ./src/, so this workaround wouldn't help in that case. For an example, see https://github.com/OliverJAsh/unsplash-ts-project-references/tree/bad-workaround.

Does this issue occur when all extensions are disabled?: Yes

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions