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

Autoimport always imports relative paths #49994

Closed
andrewAtPaymentRails opened this issue May 16, 2018 · 3 comments
Closed

Autoimport always imports relative paths #49994

andrewAtPaymentRails opened this issue May 16, 2018 · 3 comments
Assignees
Labels
javascript JavaScript support issues *question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@andrewAtPaymentRails
Copy link

  • VSCode Version: 1.23.1
  • OS Version: MacOS 10.13.4

Steps to Reproduce:

  1. Try and import something using auto-import that is close to (near adjacent) to the file you're working in. That is to say, write the name of a class of function, then use the suggestions to add the import statement for you.

Expected behaviour:

Visual Studio Code offers the import to be relative to the project (baseUrl)

// from lib/actions/approval
import { processBatch } from 'lib/actions/batch';

Actual behaviour:

Visual Studio Code will preferentially import using relative paths with "./" and "../"

import { processBatch } from '../batch';

This is a huge problem for us because our coding convention bans relative imports. Part of the reason is there's quite a few files with the same name so an import from "bank" could refer to 4 different files. Relative imports make it impossible to tell which one you're importing at a glance. You need to consider where you are in the tree already, know where that file sits relative to the one you're importing and then doing the mental gymnastics to figure out how the paths resolve. Relative paths might as well be called obfuscated paths.

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

@vscodebot vscodebot bot added the javascript JavaScript support issues label May 16, 2018
@usernamehw
Copy link
Contributor

In Insiders version there is a setting (TypeScript 2.9+):

"typescript.preferences.importModuleSpecifier": "non-relative",

@mjbvz mjbvz closed this as completed May 16, 2018
@mjbvz mjbvz added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label May 16, 2018
@Frikki
Copy link

Frikki commented Jun 26, 2018

VSCode Version 1.25.0-insider auto-imports my node_modules using relative paths.

// Illustration
import { Foo } from '../../../node_modules/foo'

@microsoft microsoft locked as resolved and limited conversation to collaborators Jun 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript JavaScript support issues *question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

4 participants