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

import suggestion for node modules includes entire path #52089

Closed
no-stack-dub-sack opened this issue Jun 16, 2018 · 15 comments
Closed

import suggestion for node modules includes entire path #52089

no-stack-dub-sack opened this issue Jun 16, 2018 · 15 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code) verified Verification succeeded
Milestone

Comments

@no-stack-dub-sack
Copy link

no-stack-dub-sack commented Jun 16, 2018

  • VSCode Version: 1.25.0-insider
  • OS Version: Windows 7 Enterprise

image

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:

  1. create project with lodash as dependency (or another package)
  2. write a function or expression that requires an export from the package

Does this issue occur when all extensions are disabled?: Yes

@vscodebot
Copy link

vscodebot bot commented Jun 16, 2018

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@vscodebot vscodebot bot added the javascript JavaScript support issues label Jun 16, 2018
@no-stack-dub-sack
Copy link
Author

no-stack-dub-sack commented Jun 16, 2018

now that I'm browsing though other issues, looks related to #52022

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 18, 2018

@no-stack-dub-sack Did you manually install @types/lodash? How did you install node_modules in the first place?

@mjbvz mjbvz added the info-needed Issue requires more information from poster label Jun 18, 2018
@no-stack-dub-sack
Copy link
Author

@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?

@no-stack-dub-sack
Copy link
Author

@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'

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 20, 2018

Same as microsoft/TypeScript#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?

@no-stack-dub-sack
Copy link
Author

no-stack-dub-sack commented Jun 25, 2018

@mjbvz Sure:

  • I am opening a folder
  • I do not have a jsconfig.json, all my files are .ts extensions, but the tsconfig does define allowJs as true
  • node_modules is at the project root, where I also have src and types directories
  • src contains client and server directories (this is a full-stack node / TS project)
  • package.json and tsconfig are also at the project root alongside src, node_modules, and types
  • the project builds into a .gitignored dist directory, also at the root level
  • all in all, a pretty standard setup, and again, this behavior is new - in months of using VS Code prior to this (with the same setup / project), the behavior had always been as described above until the 1.25 update

Let me know if you need more info

@skevy
Copy link

skevy commented Jun 26, 2018

I'm also running into this same problem, and have a very standard TS project setup. This started happening on 2.9.2

@ghost
Copy link

ghost commented Jun 26, 2018

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.

@krokofant
Copy link

@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"
  ]
}

@ghost
Copy link

ghost commented Jun 27, 2018

@krokofant Thanks! I can only reproduce that on windows for some reason.

@ghost
Copy link

ghost commented Jul 3, 2018

Fixed by microsoft/TypeScript#25364. @mjbvz Could you close this?

@mjbvz mjbvz added this to the July 2018 milestone Jul 3, 2018
@mjbvz mjbvz added bug Issue identified by VS Code Team member as probable bug upstream Issue identified as 'upstream' component related (exists outside of VS Code) and removed info-needed Issue requires more information from poster labels Jul 3, 2018
@mjbvz
Copy link
Collaborator

mjbvz commented Jul 3, 2018

Thanks @andy-ms!

@mjbvz mjbvz closed this as completed Jul 3, 2018
@djensen47
Copy link

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.

@schester44
Copy link

I'm having this issue for all imports and i'm not using TS at all.

@microsoft microsoft locked as resolved and limited conversation to collaborators Jul 31, 2018
@roblourens roblourens added the verified Verification succeeded label Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code) verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

7 participants