swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.93k stars 1.21k forks source link

`jsc.paths` transform produces absolute paths (Windows only) #5165

Closed colin969 closed 1 year ago

colin969 commented 2 years ago

Describe the bug

jsc.paths transformation produces absolute paths instead of relative paths. This only occurs on Windows, the paths are relative when run on Linux.

Example project: https://github.com/colin969/swc-issue-01-colin969

npm run build for building

Input code

No response

Config

{
  "exclude": [
    "node_modules/**"
  ],
  "module": {
    "type": "commonjs",
    "strict": true,
    "noInterop": true
  },
  "jsc": {
    "target": "es2018",
    "baseUrl": ".",
    "paths": {
      "@modules/import": ["./src/import.ts"]
    },
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "transform": {
      "decoratorMetadata": true
    }
  }
}

Playground link

No response

Expected behavior

./build/main.js output of

"use strict";
const _import = require("./import");
console.log(_import.test);

Actual behavior

./build/main.js output of

"use strict";
const _import = require("C:/Data/Projects/swc-bug/src/import");
console.log(_import.test);

Where C:/Data/Projects/swc-bug is the project path

Version

1.2.211

Additional context

No response

tiavina-mika commented 1 year ago

Facing the same issue. Have you found a solution?

colin969 commented 1 year ago

Nope, had to go back to ttypescript and only use SWC for the frontend w/ webpack.

kdy1 commented 1 year ago

Seems like this is fixed. I bought a Windows device and could reproduce this, but I couldn't reproduce it with a latest @swc/core. I'll close this issue with a PR adding a test for it

swc-bot commented 1 year ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.