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

Unable to use 'in my stats' from browserslist #8985

Open
taras-turchenko-moc opened this issue May 27, 2024 · 2 comments
Open

Unable to use 'in my stats' from browserslist #8985

taras-turchenko-moc opened this issue May 27, 2024 · 2 comments
Labels

Comments

@taras-turchenko-moc
Copy link

taras-turchenko-moc commented May 27, 2024

Describe the bug

Hi guys. I use webpack swc-loader + browserslist with my stats query but swc fails to parse targets. I made a reproduction using swc cli

Here is an error

> [email protected] build
> swc --sync ./src/test.ts

thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_preset_env-0.207.1/src/lib.rs:49:60:
failed to parse targets: failed to convert target query to version data

Caused by:
    0: failed to execute query
    1: failed to resolve browserslist query: ["last 4 chrome version", "last 4 firefox version", "last 4 edge version", ">= 0.1% in my stats and last 2 years", "Firefox ESR", "not dead"]
    2: failed to parse the rest of input: ...' stats and last 2 years, Firefox ESR, not dead'
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failed to handle: failed to parse targets: failed to convert target query to version data

Caused by:
    0: failed to execute query
    1: failed to resolve browserslist query: ["last 4 chrome version", "last 4 firefox version", "last 4 edge version", ">= 0.1% in my stats and last 2 years", "Firefox ESR", "not dead"]
    2: failed to parse the rest of input: ...' stats and last 2 years, Firefox ESR, not dead'
Error: Failed to compile 1 file with swc.
    at Object.assertCompilationResult (/Users/master/Projects/swc-browserslist-issue/node_modules/@swc/cli/lib/swc/util.js:164:15)
    at files (/Users/master/Projects/swc-browserslist-issue/node_modules/@swc/cli/lib/swc/file.js:205:19)
    at async _default (/Users/master/Projects/swc-browserslist-issue/node_modules/@swc/cli/lib/swc/file.js:224:9)

Input code

No response

Config

{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "dynamicImport": true,
      "decorators": true,
      "decoratorsBeforeExport": true
    },
    "transform": {
      "decoratorMetadata": true
    }
  },
  "env": {
    "targets": [
      "last 4 chrome version",
      "last 4 firefox version",
      "last 4 edge version",
      ">= 0.1% in my stats and last 2 years",
      "Firefox ESR",
      "not dead"
    ]
  }
}

Playground link (or link to the minimal reproduction)

https://github.com/taras-turchenko-moc/swc-browserslist-issue

SWC Info output

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 23.5.0: Wed May  1 20:17:33 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6031
    CPU: (14 cores)
        Models: Apple M3 Max

Binaries:
    Node: 20.10.0
    npm: 10.2.3
    Yarn: 1.22.21
    pnpm: N/A

Relevant Packages:
    @swc/core: 1.5.7
    @swc/helpers: N/A
    @swc/types: 0.1.7


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

Next.js info:
    output: N/A

Also issue reproduces on node:20.10.0-bullseye docker image with amd arch

Expected behavior

SWC builds code with targets support based on my browsers usage

Actual behavior

No response

Version

@swc/core: 1.5.7

Additional context

To reproduce:

  1. Pull repo
  2. npm install
  3. npm run build
@taras-turchenko-moc
Copy link
Author

taras-turchenko-moc commented May 27, 2024

Also, browserslist queries are valid. Here supported browsers using by my query

npx browserslist --stats=./browserslist-stats.json
and_chr 124
chrome 125
chrome 124
chrome 123
chrome 122
edge 125
edge 124
edge 123
edge 122
firefox 126
firefox 125
firefox 124
firefox 123
firefox 115
firefox 102
ios_saf 17.5
ios_saf 17.4
ios_saf 17.3
ios_saf 17.2
ios_saf 17.1
ios_saf 17.0
ios_saf 16.6-16.7
ios_saf 16.5
ios_saf 16.4
ios_saf 16.3
ios_saf 16.2
ios_saf 16.1
ios_saf 16.0
safari 17.5
safari 17.4
safari 17.3
safari 17.2
safari 17.1
safari 17.0
safari 16.6
safari 16.5
safari 16.4
safari 16.3
safari 16.2
safari 16.1
safari 16.0
safari 15.6

@Themezv
Copy link
Contributor

Themezv commented May 28, 2024

I think this problem caused by limitations of rust ported browserslist

https://github.com/browserslist/browserslist-rs?tab=readme-ov-file#limitations

You can use original browserslist in your webpack config and pass it to swc. Something like https://lightningcss.dev/docs.html#with-webpack

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

2 participants