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

Project references are not picked up (1) #80423

Closed
OliverJAsh opened this issue Sep 5, 2019 · 8 comments
Closed

Project references are not picked up (1) #80423

OliverJAsh opened this issue Sep 5, 2019 · 8 comments
Assignees

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Sep 5, 2019

  • VSCode Version: 1.38.0
  • OS Version: 10.14.6
  • TypeScript version: tested with both 3.5.2 and 3.6.2

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'

image

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

Potentially related:

@andrewbranch
Copy link
Member

andrewbranch commented Sep 5, 2019

@OliverJAsh did you run a tsc -b first? At the moment, declaration files need to be written to disk in order for TS Server to know about symbols from referenced projects. (Changing that is in-progress, targeted for 3.7.)

(I also find that after doing a build from the command line, sometimes I still need to restart TS Server to see the results in VS Code.)

@OliverJAsh
Copy link
Contributor Author

I did all of those things, unfortunately to no avail. I even checked the TS server log to see if I could spot anything particularly odd, also to no avail.

@andrewbranch
Copy link
Member

@OliverJAsh hold on, helpers/functions refers to something inside node_modules (or a path mapping, of which you have none in the sample you posted). I think you meant to use a relative path, unless I missed an important piece somewhere?

@OliverJAsh
Copy link
Contributor Author

baseUrl is what holds it together here. It works if you don't use project references. Same example but without project references: https://github.com/OliverJAsh/unsplash-ts-project-references/tree/no-project-references

@OliverJAsh OliverJAsh changed the title Not detecting referenced TypeScript project Project references are not picked up (1) Sep 5, 2019
@OliverJAsh
Copy link
Contributor Author

The more I play with project references, the more it seems like they simply don't work with VS Code. Here's a similar but separate issue I just filed: #80438.

@mjbvz
Copy link
Collaborator

mjbvz commented Sep 9, 2019

@OliverJAsh In your example, src/main is not part of any project known to VS Code (just run TypeScript: Go to project configuration with the file open to check this) It is only part of the tsconfig-src.json project, which VS Code does not load automatically. We currently only load projects in files called tsconfig.json

In tsconfig.json, if I change files to "files": ["src/main.ts"] then everything seems to work

Screen Shot 2019-09-09 at 10 49 26 AM

Closing this as a configuration question. microsoft/TypeScript#33094 would let you specify other config file names instead of tsconfig.json

@mjbvz mjbvz closed this as completed Sep 9, 2019
@OliverJAsh
Copy link
Contributor Author

It is only part of the tsconfig-src.json project, which VS Code does not load automatically

Correct, but tsconfig.json references tsconfig-src.json. So if VS Code discovers tsconfig.json, why does not it pick up the referenced project? I thought this was the whole point of TS project references.

@mjbvz
Copy link
Collaborator

mjbvz commented Sep 9, 2019

Good point. I was having trouble understanding what the intention was in the example.

This looks like another case of microsoft/TypeScript#30823 then. If you don't think this is the case, please open a new issue against TypeScript

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants