Skip to content

Aliases (Paths) Not Being Replaced #2523

@adrians5j

Description

@adrians5j

Describe the bug
Just started playing with SWC and I I'd just like to say this is an amazing tool. Just amazed how it's fast and how much work has been put into it. 🙏🏻

So, in my code, I have ~/........ import statements, but, once the SWC has done its magic, these are replaced with correct paths - only when I set "type": "commonjs" in my .swcrc file. Otherwise, they just stay the same.

Input code

image

So, this is the resulting code. As we can see, the import paths haven't changed (~ is still here).

image

But, if I were to use the commonjs module type, then I'd see the path built correctly:

image

Config

commonjs works (paths are changed correctly):

{
  "jsc": {
    "parser": {
      "syntax": "typescript"
    },
    "target": "es2020",
    "paths": {
      "~/*": ["./src/*"]
    },
    "baseUrl": "."
  },
  "module": {
    "type": "commonjs"
  }
}

This one does not work:

{
  "jsc": {
    "parser": {
      "syntax": "typescript"
    },
    "target": "es2020",
    "paths": {
      "~/*": ["./src/*"]
    },
    "baseUrl": "."
  }
}

Expected behavior
The paths to be correctly replaced.

Version
The version of @swc/core: 1.2.102

Additional context
Checked a couple of issues reported by other users (#2126, #2050), those didn't provide any clues unfortunately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions