Skip to content

auto import always uses relative (to the current file) module paths in presense of baseUri #21860

Open

Description

back in a day it used to be different

  • at first it was always an absolute path (that is without "./" or "../" in it) relative to the baseUri
  • then starting at some point it began to always show a popup with 2 options: absolute or relavive
  • now (since like a week ago or so) it just always uses a relative path with "./" and "../" to the current file no matter what, without asking, which is very frustrating and annoying

how can i get the auto import to use absolute paths like it was back in the day?

Activity

  1. zpdDG4gta8XKpMCd commented on Feb 12, 2018

    @zpdDG4gta8XKpMCd
    Author

    i am talking about import on completion, because i cannot opt out from completion itself and import just comes with it

    there are a few reasons i don't want ./ and ../ in my module paths:

    • i compile the same code for AMD and CommonJs, and absolute paths are a common ground
    • relative paths are a pain to maintain (move files around)

    so how can i get the import on completion to use absolute paths (relative to baseUri) please?

  2. alextreppass commented on May 15, 2018

    @alextreppass

    Hi Andy (Andrewkraft) (@Andy-MS) - did #20619 allow for imports to use baseUrl paths? I see it's marked as closed via #22236, but I'm not sure whether that added the proposed option

    Thanks

  3. mhegazy commented on May 15, 2018

    @mhegazy
    Contributor

    This should be exposed in VSCode (insiders as of now) under "typescript.preferences.importModuleSpecifier": "non-relative"

  4. jabsatz commented on Sep 20, 2018

    @jabsatz

    This keeps happening even with that option enabled, I read in another issue that the completion uses whichever path is shortest as a string and that you were looking into making that into an option. Any updates on that?

  5. jabsatz commented on Sep 20, 2018

    @jabsatz

    jsconfig.json:

    {
    	"compilerOptions": {
    		"target": "esnext",
    		"allowSyntheticDefaultImports": true,
    		"baseUrl": "./src",
    		"paths": {
    			"*": ["*"]
    		},
    	},
    	"exclude": ["node_modules", "build"]
    }
    

    settings:

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

    If I'm correct, this should resolve packages non-relatively, and it does, but only sometimes. Say for example my folder structure is somewhat like this:

    src/
    ├── components/
    │   ├── common/
    │   │   └── Dialog.jsx
    │   └── profile/
    │       └── Profile.jsx
    └── utils/
        └── calc.js
    

    If I write Dialog in Profile.jsx, intellisense will suggest auto-import from "../common/Dialog", however, if I try to write calc, instead of suggesting "../../utils/calc" it just suggests "utils/calc" (as I expect).

  6. jabsatz commented on Sep 20, 2018

    @jabsatz

    No, should I?

  7. jabsatz commented on Sep 21, 2018

    @jabsatz

    That did the trick! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions