
Not sure if I should be opening this since this is a part of the insiders build, but since my most recent update, I've noticed that the import suggestions for installed modules like lodash include the entire path to the module, rather than just import something from 'module'. In the screenshot above you can see what I mean, the comment at the top is the result of accepting the suggestion, when it could simply be
import startCase from 'lodash';
EDIT: I've also just noticed that it seems to be suggesting the type rather than the actual function that I need. This may be at the heart of the problem?
Steps to Reproduce:
Does this issue occur when all extensions are disabled?: Yes
(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:
now that I'm browsing though other issues, looks related to #52022
@no-stack-dub-sack Did you manually install @types/lodash? How did you install node_modules in the first place?
@mjbvz lodash is a part of the application scaffold I am using at work, so I never installed lodash at all, and I can't see the package.json of the generator that produces the node_modules for me, but I'm guessing @types/lodash is being installed separately from lodash rather than using the built in types since it makes it in to the @types directory. However, in the past (until I updated), the suggestion always produced an import without the complete path — is this the new expected behavior when types are installed separately?
@mjbvz Also, for another example - I just installed another package to the project myself via yarn which has it's own index.d.ts file. When I try to import a type from that package, I get the same behavior - it suggests '../../complete/path/to/node_modules/package' rather than just 'package'
Same as https://github.com/Microsoft/TypeScript/issues/23230
Please share more information about your project structure. Are you opening a loose file or are you opening a folder? Do you have a jsconfig.json? What is the directory structure like? Where is node_modules located and where is the js file located?
@mjbvz Sure:
Let me know if you need more info
I'm also running into this same problem, and have a very standard TS project setup. This started happening on 2.9.2
I'm having trouble reproducing this -- could you try and come up with a particular set of files that reproduces the issue? Presumably this can be reproduced with a setup like the following?
node_modules/xxx/index.d.ts
export const xxx: number;
src/a.ts
/// <reference types="xxx" />
xxx // Import fix here
tsconfig.json:
{
"compilerOptions": {
<<settings needed to reproduce the issue here>>
}
}
With just those files (and empty compilerOptions) I'm not reproducing the issue with typescript@next.
@andy-ms The issue exists in a fresh Angular install.
npm install -g @angular/cli
ng new hello-world
and edit app.component.ts or some other file with node_modules import.
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": []
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
@krokofant Thanks! I can only reproduce that on windows for some reason.
Fixed by Microsoft/TypeScript#25364. @mjbvz Could you close this?
Thanks @andy-ms!
So I take it this did _not_ make it into 1.25.1?
Do we have to wait until the September release to see the fix for this regression?
Thanks for any insights.
I'm having this issue for all imports and i'm not using TS at all.
Most helpful comment
I'm also running into this same problem, and have a very standard TS project setup. This started happening on 2.9.2