Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot find module" when using project references #36708

Closed
OliverJAsh opened this issue Feb 10, 2020 · 3 comments · Fixed by #37239
Closed

"Cannot find module" when using project references #36708

OliverJAsh opened this issue Feb 10, 2020 · 3 comments · Fixed by #37239
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@OliverJAsh
Copy link
Contributor

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

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 21, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Feb 21, 2020
sheetalkamat added a commit that referenced this issue Mar 6, 2020
@sheetalkamat sheetalkamat added the Fix Available A PR has been opened for this issue label Mar 6, 2020
sheetalkamat added a commit that referenced this issue Mar 13, 2020
…eferenced by one of the project references (#37239)

* Add test where file from referenced project of solution belongs to inferred project instead of referenced project

* Try to find project from project references if the default config project is solution
Fixes #36708

* Add test to verify the correct collection of projects

* Handle when default config project is indirectly referenced in the solution

* Include public API tests in unittests

* Make sure default project for script info is calculated correctly

* Handle reload projects

* Ensure to load solution project tree when project is referenced by solution

* Find all refs when the file is referenced via d.ts

* Some comments per feedback

* Fix typo
@dtothefp
Copy link

dtothefp commented Apr 9, 2020

Hi I'm having this same issue. Is it somehow resolved?

@ysfaran
Copy link

ysfaran commented Sep 6, 2021

Still here and struggling.. the code works fine but intellisense is not working and the error shows up in VSCode..

@cmcnicholas
Copy link

yep still getting the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
6 participants