Parcel: VS Code, import navigation when using aliases

Created on 16 Dec 2018  ·  3Comments  ·  Source: parcel-bundler/parcel

❔ Question

When I define some aliases inside my package.json

  "alias": {
    "assets": "./src/assets",
    "utils": "./src/globals/utils"
  }

Then I can do for example:

impot {someComponent} from 'utils';

VS code does not navigate to utils when I attempt to ctrl+click into it, while it would if I used a normal, non-aliased path.
Do you know a workaround to make this work?

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.10.3
| Node | 10
| npm/Yarn | 6.x
| Operating System | Win7 x64

Question Stale

Most helpful comment

According to this comment https://github.com/Microsoft/vscode/issues/36495#issuecomment-338864671, adding a jsconfig.json file into your src folder should work:

{
    "compilerOptions": {
        "target": "ES6",
        "baseUrl": ".",
        "paths": {
            "assets": ["src/assets"],
            "utils": ["src/globals/utils"],
        }
    },
    "include": [
        "src/**/*"
    ]
}

All 3 comments

According to this comment https://github.com/Microsoft/vscode/issues/36495#issuecomment-338864671, adding a jsconfig.json file into your src folder should work:

{
    "compilerOptions": {
        "target": "ES6",
        "baseUrl": ".",
        "paths": {
            "assets": ["src/assets"],
            "utils": ["src/globals/utils"],
        }
    },
    "include": [
        "src/**/*"
    ]
}

I guess you meant as a "sibling" of src folder, in essence in the root of my project.
That worked, but without "target ES6", for some reason that line screws it.

So this is how I do in jsconfig.json:

{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"components/*": ["src/components/*"],
"assets/*": ["src/assets/*"],
"utils.js": ["src/globals/utils.js"]
}
},
"include": [
"src/*/"
]
}

Reason: I define some aliases because I don't like ../../../bla/bla
Components are followed ok, assets are not, for example .svg aren't followed.
Also .scss are not followed, as well as .css.
They are followed from within their own format though, .scss to other .scss or css, but not crossing file extension, so for example from .js to .scss.
For example, my App.js contains:
import './App.scss';

When doing ctrl+click, it doesn't follow.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Niggler picture Niggler  ·  3Comments

oliger picture oliger  ·  3Comments

donaldallen picture donaldallen  ·  3Comments

adamreisnz picture adamreisnz  ·  3Comments

philipodev picture philipodev  ·  3Comments