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 not working for modules that are indirect dependencies #35023

Closed
jcormont opened this issue Nov 10, 2019 · 3 comments
Closed

Auto-import not working for modules that are indirect dependencies #35023

jcormont opened this issue Nov 10, 2019 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@jcormont
Copy link

TypeScript Version: 3.7.2

Issue

I noticed that auto-import in VS Code stopped working for some of my projects after updating to TS 3.7 (everything worked in 3.6). After some digging I noticed that the Language Server logs included the line "forEachExternalModuleToImportFrom: filtered out XX modules by package.json contents".

In short, any module that isn't directly included in package.json seems to be no longer considered for auto-import by TS 3.7. This includes indirect dependencies: modules that are dependencies of modules that are in fact included in package.json.

For example, module 'my-web-lib' that has a dependency on 'my-lib' is in my package.json; but if I don't also include 'my-lib' in my package.json explicitly, the Language Server will no longer consider auto-importing from 'my-lib'. This used to work fine, which I found useful for 'meta' packages that import a bunch of versioned dependencies in one go, or perhaps a combined node/web package that's imported indirectly using web-specific or node-specific packages without having to mention (and version) the final packages.

Now that I know what's going on, this seems like a trivial issue ('just add the indirect dependency to my package'). This is possibly a new feature in TS 3.7, but I can't find it in the change logs. Just in case this is an unintended side effect of some other change, I'll create this issue here. Also in case others are confused as well, this issue might help them figure out what's going on.

Code
This issue is related to NPM dependencies, so requires a bit of setup. Essentially, add a package.json dependency (or dev dependency) that itself has a dependency on a module that exports TypeScript types. Then try to import a symbol from the second-level dependency.

I have a few specific examples but since I'm updating my repos to eradicate this issue, I won't leave any links here for now; please let me know if you need me to set up a repo.

Expected behavior:

As above, auto-import like it used to work in 3.6.

Actual behavior:

As above, indirect dependencies are no longer considered for auto-import.

Search Terms: Auto-import indirect dependencies NPM modules d.ts

@jcormont jcormont changed the title Auto-import not working for modules that are second-level dependencies Auto-import not working for modules that are indirect dependencies Nov 10, 2019
@fatcerberus
Copy link

This appears to be deliberate: #32517

You're right that this seemingly isn't mentioned in the release notes, though.

@jcormont
Copy link
Author

Yes, that's the relevant PR. Good find. I suppose this got marked as a 'perf' fix only, not worth mentioning in change logs, while in practice this could be somewhat of a breaking change (to the editing experience, that is).

I see the issue has a "Update Docs on Next Release" label so I guess that's worth following up on. Issue can be closed if no code changes are considered. Thanks

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Nov 12, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants