You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove NgModule import (the @NgModule will be highlighted with an error)
Place cursor on the @NgModule. Here expected behavior is that the light bulb would appear and suggest to add missing import. In reality nothing happens. I am still able to add import manually but it's impossible to use auto import feature for this. When entering import manually Intellisense works without any problems.
This might seem like a minor problem but the example is just a small extract from a big project. It seems that VSCode (or TS server) is not checking for possible typings in node_modules. In the end we have to add imports manually everywhere which is very time consuming and simply kills productivity.
Does this issue occur when all extensions are disabled?: Yes
I confirmed this with typescript@3.4.0-dev.20190221
There do not appear to be any errors in the ts server logs. Once you add any @angular/core import to the file, then we do properly suggest the import quick fix
This is an intentional performance/helpfulness trade-off.
We don't eagerly consume all.d.ts files from node_modules - doing so would be prohibitively expensive in a world where there are regularly possible thousands of definition files in node_modules.
When the Angular .d.ts file isn't consumed, we have no way of knowing that NgModule happens to come from @angular/core, thus can't suggest that auto-import.
I have this issue as well, and I'm confused as to why it was closed without further discussion. Is there any workaround you can suggest? For example, I'm using the wonderful fp-ts library by gcanti, and I'm constantly having to type out every import - I don't remember this happening before v3.x.
I literally explained why it works the way it does, then you commented, now I'm responding. Not sure how that's "without further discussion" ? 😕
I have this issue as well ... I'm constantly having to type out every import
It sounds like you're having a different issue. Once you have the first import, subsequent imports to the same library should be available for automatic importing. Can you (in a new report) outline the steps to reproduce the problem you're describing?
I am experiencing the same problem as Christian (@christianbradley) describes. Unfortunately I wasn't able to create a 100% reproduction case, so decided not to post it.
Ryan Cavanaugh (@RyanCavanaugh) - by "it was closed without further discussion" I'm just referring to the fact that the feature was set to "closed" - without further discussion.
With a library like fp-ts - everything is pulled from lib, ie:
import{Option,fromNullable}from'fp-ts/lib/Option'
It does look like once I import from that file, anything exported from that file seems to generally be available for auto-import. However, if I start typing out another export from that library, say, scanRight from fp-ts/lib/Array, it doesn't suggest the import, and quick fix doesn't show it either.
Oddly, some exports from other modules are suggested - I'm assuming this is because are referenced by Array.d.ts in some manner. ie: fp-ts/lib/Either
If there was a way to inform the compiler to eager-load everything from a specific folder, module, etc, that would be wonderful.
As a side question - was this always how the compiler worked? I feel like this has only happened recently, but I could be wrong.
Non working auto import suggestions for packages in node_modules confirmed for me in react blank project (yarn create react-app vscode-issue-30033 --template typescript)
Environment OS Version: Linux manjaro 5.4.97-1-MANJARO Code Version:
Toliak those don’t work because those modules aren’t referenced from the package root. When we see your package.json has "rxjs" in it, for example, we look at rxjs’s package.json for the file listed by types, and load that. We also load everything it imports/references, and those things become available for auto import. What we don’t do is a recursive directory search, looking for other typings files. That would be extremely expensive. It’s an unfortunate limitation, but it is expected behavior for now.
Toliak those don’t work because those modules aren’t referenced from the package root. When we see your package.json has "rxjs" in it, for example, we look at rxjs’s package.json for the file listed by types, and load that. We also load everything it imports/references, and those things become available for auto import. What we don’t do is a recursive directory search, looking for other typings files. That would be extremely expensive. It’s an unfortunate limitation, but it is expected behavior for now.
Why there cant be node_modules+1 recursive lookup not node_modules+n recursive and this can be adjusted via config? So all node_modules root packages are available via auto suggest??? not only packages listed in package.json. This is really annoying.
so some_package and some_other_package now will be available for autocomplete, but not some_dependency?
I think its very often to install some package which has dependencies which we will use in project but they cant be auto-suggested until added into root package.json but i dont want to specify them only for vscode autosuggest because its an approach to have package which installs needed deps in project.
Why there cant be node_modules+1 recursive lookup not node_modules+n recursive and this can be adjusted via config?
We're not super interested to spend complexity or performance budget here. There are many more impactful issues to address first. You can write an import, once, to get the module into your program, after which point auto-import will see them.
Activity
mjbvz commentedon Feb 22, 2019
I confirmed this with typescript@3.4.0-dev.20190221
There do not appear to be any errors in the ts server logs. Once you add any
@angular/coreimport to the file, then we do properly suggest the import quick fixRyanCavanaugh commentedon Feb 27, 2019
This is an intentional performance/helpfulness trade-off.
We don't eagerly consume all
.d.tsfiles fromnode_modules- doing so would be prohibitively expensive in a world where there are regularly possible thousands of definition files innode_modules.When the Angular
.d.tsfile isn't consumed, we have no way of knowing thatNgModulehappens to come from@angular/core, thus can't suggest that auto-import.christianbradley commentedon Feb 28, 2019
I have this issue as well, and I'm confused as to why it was closed without further discussion. Is there any workaround you can suggest? For example, I'm using the wonderful
fp-tslibrary bygcanti, and I'm constantly having to type out every import - I don't remember this happening before v3.x.RyanCavanaugh commentedon Feb 28, 2019
I literally explained why it works the way it does, then you commented, now I'm responding. Not sure how that's "without further discussion" ? 😕
It sounds like you're having a different issue. Once you have the first import, subsequent imports to the same library should be available for automatic importing. Can you (in a new report) outline the steps to reproduce the problem you're describing?
KirillMetrik commentedon Feb 28, 2019
I am experiencing the same problem as Christian (@christianbradley) describes. Unfortunately I wasn't able to create a 100% reproduction case, so decided not to post it.
christianbradley commentedon Mar 1, 2019
Ryan Cavanaugh (@RyanCavanaugh) - by "it was closed without further discussion" I'm just referring to the fact that the feature was set to "closed" - without further discussion.
With a library like fp-ts - everything is pulled from
lib, ie:It does look like once I import from that file, anything exported from that file seems to generally be available for auto-import. However, if I start typing out another export from that library, say,
scanRightfromfp-ts/lib/Array, it doesn't suggest the import, and quick fix doesn't show it either.Oddly, some exports from other modules are suggested - I'm assuming this is because are referenced by
Array.d.tsin some manner. ie:fp-ts/lib/EitherIf there was a way to inform the compiler to eager-load everything from a specific folder, module, etc, that would be wonderful.
As a side question - was this always how the compiler worked? I feel like this has only happened recently, but I could be wrong.
unional commentedon Jun 4, 2019
Ryan Cavanaugh (@RyanCavanaugh) is it possible to read only those specified in package.json and go down transitively?
Domiii commentedon Jan 27, 2020
Any progress on this?
It almost looks like the team has largely deprioritized this issue?
I am also strongly in favor of Homa Wong (@unional)'s suggestion, same as suggested here.
ashceo commentedon Feb 16, 2020
+1
andrewbranch commentedon Mar 3, 2020
Just for clarity of record keeping, #36042 tracks the reconsideration of this issue.
Toliak commentedon Mar 7, 2021
Non working auto import suggestions for packages in node_modules confirmed for me in react blank project (
yarn create react-app vscode-issue-30033 --template typescript)Environment
OS Version:
Linux manjaro 5.4.97-1-MANJAROCode Version:
TypeScript Version: 4.2.3
All extensions are disabled.
Variant 1
rxjs@7.0.0-beta.12package.Type somewhere
concatMap. Expected: suggestionimport { concatMap } from 'rxjs/operators';Actual: no suggestions...

Variant 2
ttypescript@1.5.12package.Type somewhere
loadTypeScript. Expected suggestionimport {loadTypeScript} from 'ttypescript/lib/loadTypescript';Actual: nothing..

Variant 3
mtasa-lua-types@0.1.6package.Type somewhere
bindKey. Expected suggestion:import {bindKey} from 'mtasa-lua-types/types/mtasa/client/function/input';Actual: no suggestions again

What about another IDE?
I am frustrated when I see that behavior in VSCode. In WebStorm, for example, all variants works perfectly.
andrewbranch commentedon Mar 8, 2021
Toliak those don’t work because those modules aren’t referenced from the package root. When we see your package.json has
"rxjs"in it, for example, we look at rxjs’s package.json for the file listed bytypes, and load that. We also load everything it imports/references, and those things become available for auto import. What we don’t do is a recursive directory search, looking for other typings files. That would be extremely expensive. It’s an unfortunate limitation, but it is expected behavior for now.ashceo commentedon Mar 9, 2021
Why there cant be node_modules+1 recursive lookup not node_modules+n recursive and this can be adjusted via config? So all node_modules root packages are available via auto suggest??? not only packages listed in package.json. This is really annoying.
I mean:
package.json:
"some_package": "*",so some_package and some_other_package now will be available for autocomplete, but not some_dependency?
I think its very often to install some package which has dependencies which we will use in project but they cant be auto-suggested until added into root package.json but i dont want to specify them only for vscode autosuggest because its an approach to have package which installs needed deps in project.
RyanCavanaugh commentedon Mar 9, 2021
We're not super interested to spend complexity or performance budget here. There are many more impactful issues to address first. You can write an import, once, to get the module into your program, after which point auto-import will see them.