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

Auto import paths dont handle source of projectReferenceRedirect in editor #34677

Closed
sheetalkamat opened this issue Oct 23, 2019 · 9 comments · Fixed by #37482
Closed

Auto import paths dont handle source of projectReferenceRedirect in editor #34677

sheetalkamat opened this issue Oct 23, 2019 · 9 comments · Fixed by #37482
Labels
Fix Available A PR has been opened for this issue

Comments

@sheetalkamat
Copy link
Member

https://github.com/vilic/bug-repros/tree/typescript-32028

3.8.0-dev.20191023
image
3.6.3
image

Originally posted by @vilic in #32028 (comment)

@sheetalkamat
Copy link
Member Author

Also from the issue comment

The auto import path seems to be affected by this change. E.g. previously I have a module of which the auto import path is shared but now it's shared/src/library.
The shared module is a linked module which is also one of the referenced projects, it has package.json with types set to bld/library/index.d.ts and I guess that's why the auto import path worked as shared instead of shared/bld/library.

@sheetalkamat
Copy link
Member Author

@vilic the repro you provided has some issues.. I don't see module resolution happening..

c:\temp\bug-repros>node node_modules\typescript\lib\tsc.js -v
Version 3.8.0-dev.20191023

c:\temp\bug-repros>node node_modules\typescript\lib\tsc.js -b -v --traceResolution
[11:10:54 AM] Projects in this build:
    * shared/src/library/tsconfig.json
    * app/src/program/tsconfig.json
    * tsconfig.json

[11:10:54 AM] Project 'shared/src/library/tsconfig.json' is out of date because output file 'shared/bld/library/index.js' does not exist

[11:10:54 AM] Building project 'c:/temp/bug-repros/shared/src/library/tsconfig.json'...

[11:10:55 AM] Project 'app/src/program/tsconfig.json' is out of date because output file 'app/bld/program/bar.js' does not exist

[11:10:55 AM] Building project 'c:/temp/bug-repros/app/src/program/tsconfig.json'...

======== Resolving module 'shared' from 'c:/temp/bug-repros/app/src/program/bar.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module 'shared' from 'node_modules' folder, target file type 'TypeScript'.
Directory 'c:/temp/bug-repros/app/src/program/node_modules' does not exist, skipping all lookups in it.
Directory 'c:/temp/bug-repros/app/src/node_modules' does not exist, skipping all lookups in it.
Directory 'c:/temp/bug-repros/app/node_modules' does not exist, skipping all lookups in it.
File 'c:/temp/bug-repros/node_modules/shared.ts' does not exist.
File 'c:/temp/bug-repros/node_modules/shared.tsx' does not exist.
File 'c:/temp/bug-repros/node_modules/shared.d.ts' does not exist.
Directory 'c:/temp/bug-repros/node_modules/@types' does not exist, skipping all lookups in it.
Directory 'c:/temp/node_modules' does not exist, skipping all lookups in it.
Directory 'c:/node_modules' does not exist, skipping all lookups in it.
Loading module 'shared' from 'node_modules' folder, target file type 'JavaScript'.
Directory 'c:/temp/bug-repros/app/src/program/node_modules' does not exist, skipping all lookups in it.
Directory 'c:/temp/bug-repros/app/src/node_modules' does not exist, skipping all lookups in it.
Directory 'c:/temp/bug-repros/app/node_modules' does not exist, skipping all lookups in it.
File 'c:/temp/bug-repros/node_modules/shared.js' does not exist.
File 'c:/temp/bug-repros/node_modules/shared.jsx' does not exist.
Directory 'c:/temp/node_modules' does not exist, skipping all lookups in it.
Directory 'c:/node_modules' does not exist, skipping all lookups in it.
======== Module name 'shared' was not resolved. ========
app/src/program/bar.ts:1:19 - error TS2307: Cannot find module 'shared'.

1 import {foo} from 'shared';
                    ~~~~~~~~

app/src/program/index.ts:1:1 - error TS2304: Cannot find name 'foo'.

1 foo;
  ~~~


Found 2 errors.


c:\temp\bug-repros>


@sheetalkamat sheetalkamat added the Needs More Info The issue still hasn't been fully clarified label Oct 23, 2019
@vilicvane
Copy link

@sheetalkamat Are you using yarn or npm? The repro is using yarn workspaces linking projects.

@sheetalkamat
Copy link
Member Author

I have cloned and ran the tsc with nightly. If those aren't the steps to repro, please provide correct repro steps.

@vilicvane
Copy link

vilicvane commented Oct 23, 2019

@sheetalkamat Steps after clone:

  1. yarn under the project directory.
  2. yarn tsc --build (Expecting error Cannot find name 'foo'.)
  3. Open project with VSCode and open app/src/program/index.ts, and try auto fixes on identifier foo.

BTW just confirmed that setting disableSourceOfProjectReferenceRedirect as true brings back the old behavior.

@sheetalkamat sheetalkamat added Needs Investigation This issue needs a team member to investigate its status. and removed Needs More Info The issue still hasn't been fully clarified labels Oct 23, 2019
@dinofx
Copy link

dinofx commented Mar 19, 2020

Is there any way to get intellisence proposals across referenced projects when the "shared" project has a directory of type declarations? So multiple d.ts files instead of just index.d.ts.

@sheetalkamat sheetalkamat added Fix Available A PR has been opened for this issue and removed Needs Investigation This issue needs a team member to investigate its status. labels Mar 19, 2020
sheetalkamat added a commit that referenced this issue Mar 19, 2020
sheetalkamat added a commit that referenced this issue Mar 19, 2020
@sheetalkamat sheetalkamat added this to the TypeScript 3.9.0 milestone Mar 19, 2020
sheetalkamat added a commit that referenced this issue Mar 19, 2020
* Add test for project reference and auto import
Test for #34677

* Add project reference redirect to the possible file name to import if file is source of project reference redirect
Fixes the auto import suggestion when project is built

* Use fileExists that mimics presence of project reference redirect file when trying to get auto import file name
@dimikot
Copy link

dimikot commented Apr 30, 2020

This is a really awesome cool fix! Looks like, at last, In April 2020, TS & VSCode become both monorepo-friendly!

I also prepared a repro steps where IntelliSense incorrectly proposes to auto-import files from src/ instead of dist/, but I can confirm that in 3.9.1-rc it stopped reproducing.

Just in case, here are these repro examples: https://github.com/DmitryKoterov/intellisense-composite

A screenshot from default/ folder from there (TS 3.8.3, wrong behavior):

Screen Shot 2020-04-30 at 3 12 58 AM

And a screenshot from disableSourceOfProjectReferenceRedirect-true folder which sets disableSourceOfProjectReferenceRedirect=true (TS 3.8.3 still, the above behavior disappeared):

Screen Shot 2020-04-30 at 3 13 13 AM

In TS 3.9.1-rc, the 1st screenshot stopped reproducing - and it's great!

@dko-slapdash

This comment has been minimized.

@dko-slapdash

This comment has been minimized.

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

Successfully merging a pull request may close this issue.

5 participants