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

[Bug]: Using latest SWC rule, swc crash while not finding 'base_dir' #248

Closed
supercairos opened this issue Mar 29, 2024 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@supercairos
Copy link

supercairos commented Mar 29, 2024

What happened?

While running the latest version of SWC rules, it crashes with this error:

ERROR: /Users/romain/git/oidc/packages/i18n/express/BUILD:25:11: Compiling //packages/i18n/express:ts_transpile [swc packages/i18n/express/src/i18n.ts] failed: (Exit 101): swc-darwin-arm64 failed: error executing command (from target //packages/i18n/express:ts_transpile) 
  (cd /private/var/tmp/_bazel_romain/aab898f10bfeb90def8d69f3c9616e24/sandbox/darwin-sandbox/1652/execroot/com_shadow_cbp && \
  exec env - \
  external/swc_darwin-arm64/swc-darwin-arm64 compile --source-maps true --source-file-name ../src/i18n.ts --source-root packages/i18n/express --config-file bazel-out/darwin_arm64-fastbuild/bin/packages/i18n/express/.swcrc --out-file bazel-out/darwin_arm64-fastbuild/bin/packages/i18n/express/src/i18n.js packages/i18n/express/src/i18n.ts)
# Configuration: 7f308466bd98cfb2b391af4037586009214979163f843b0f91a1705af46bb64c
# Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
thread 'main' panicked at 'base_dir(``) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly. This cannot be deduced by SWC itself because SWC is a transpiler and it does not try to resolve project details. In other works, SWC does not know which directory should be used as a base directory. It can be deduced if `.swcrc` is used, but if not, there are many candidates. e.g. the directory containing `package.json`, or the current working directory. Because of that, the caller (typically the developer of the JavaScript package) should specify it. If you see this error, please report an issue to the package author.', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.38/src/path.rs:104:13

Version

Development (host) and target OS/architectures:

Output of bazel --version:
bazel 7.1.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
rules_swc-1.2.2
rules_ts-2.2.0
rules_js-1.40.0

Language(s) and/or frameworks involved:
TS

How to reproduce

No response

Any other information?

While upgrading from rules_swc-1.1.0 to rules_swc-1.2.2

@supercairos supercairos added the bug Something isn't working label Mar 29, 2024
@github-actions github-actions bot added the untriaged Requires traige label Mar 29, 2024
@supercairos supercairos changed the title [Bug]: Using latest SWC rule, swc crash while not finding 'base_dir(``)' [Bug]: Using latest SWC rule, swc crash while not finding 'base_dir' Mar 29, 2024
@supercairos
Copy link
Author

supercairos commented Mar 29, 2024

Some more info:

Version 1.2.2 works with SWC SWC_VERSION = "v1.3.75" [1.1.0 LATEST] but doesn't with LATEST_SWC_VERSION (v1.3.78)

@supercairos
Copy link
Author

Error lies between version SWC v1.3.75 and v1.3.76

@supercairos
Copy link
Author

Probably due to this fix:
swc-project/swc#7775

@supercairos
Copy link
Author

supercairos commented Mar 29, 2024

Ok, I've found the solution:

With new versions of SWC, if you specify path rewrite, you need to specify a baseUrl.

For exemple if you have this in you .swcrc:

"jsc": {
...
  "paths": {
      "i18next": [
        "./node_modules/i18next"
      ]
    },
...
}

You have to specify:

"jsc": {
...
  "baseUrl": "."
...
}

@jbedard
Copy link
Member

jbedard commented Apr 1, 2024

Thanks for following up and recording your findings 👍

@jbedard jbedard removed the untriaged Requires traige label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants