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

swc doesn't support env.target.node = "current" like babel does #9445

Open
ItamarGronich opened this issue Aug 18, 2024 · 0 comments
Open

swc doesn't support env.target.node = "current" like babel does #9445

ItamarGronich opened this issue Aug 18, 2024 · 0 comments
Labels

Comments

@ItamarGronich
Copy link

ItamarGronich commented Aug 18, 2024

Describe the bug

When setting env.target.node to "current" swc errors with:

thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/preset_env_base-0.5.1/src/query.rs:116:46:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failed to handle: internal error: entered unreachable code
Failed to compile 1 file with swc.

While babel supports the "current" keyword.

Looks like SWC only supports semver.
While babel handles the "current" keyword.

Also, it would be nicer if a better more user friendly error would be returned to the user.

Something like

Failed to parse version as semver for target: node. The value "current" is no a valid semver string.

Also, would be nice to modify the documentation to reflect what values the targets as object in swc are expected to be

Input code

// The code doesn't matter, the bug is in the configuration itself.
console.log('test')

Config

{
    "$schema": "https://swc.rs/schema.json",
    "jsc": {
        "parser": {
            "syntax": "ecmascript"
        }
    },
    "env": {
        "targets": {
            "node": "current"
        }
    }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.11&code=H4sIAAAAAAAAAwMAAAAAAAAAAAA%3D&config=H4sIAAAAAAAAA1WOSw6DMAxE95wi8pp1F71DDxEFg4LIR3ZSNULcvSEQCDt7Zvw8aycEzKzgLdY85sVLYqRrzwonG%2BQvK4DKSFakfYC%2BujPv1igXxiJthwOLc4zVOTWjrR5Ty1bOeELmZ3CPSjst%2BCR3Jx2MG2Ixz84heSz9%2BAV3qD67wKD5Uy8DxUND%2B21AkiYM3Da0bihsFYnQBrirdNsfZbqRJz4BAAA%3D

SWC Info output

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6020
    CPU: (10 cores)
        Models: Apple M2 Pro

Binaries:
    Node: 20.16.0
    npm: 10.8.1
    Yarn: N/A
    pnpm: 9.7.1

Relevant Packages:
    @swc/core: 1.7.11
    @swc/helpers: N/A
    @swc/types: 0.1.12
    

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

Any or all of these.

  1. The "current" keyword actually works and resolves the correct node version.
  2. Documentation indicates the actual expected values for object version of env.targets. Even more important if you end deciding not to support the "current" keyword.
  3. Errors are human readable and provide more information as to what went wrong and which config messed things up.

Actual behavior

SWC throws an "unreachable code" error and crashes.

The error:

thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/preset_env_base-0.5.1/src/query.rs:116:46:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failed to handle: internal error: entered unreachable code
Failed to compile 1 file with swc.

Version

1.7.11

Additional context

No response

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

No branches or pull requests

1 participant