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

[plugin-legacy] Custom usage stats in browserslist-stats.json broken #10502

Closed
7 tasks done
philbates35 opened this issue Oct 17, 2022 · 1 comment
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@philbates35
Copy link
Contributor

philbates35 commented Oct 17, 2022

Describe the bug

When I create a simple browserslist-stats.json in a Vite project root (see browserslist docs for more info), and then add a rule like covers 95% in my stats to my plugin-legacy targets, I should be able to build for production successfully.

Instead build fails with:

[vite:legacy-post-process] [BABEL] unknown file: Custom usage statistics was not provided (While processing: "base$1")
error during build:

I've spent a couple of hours looking into this, and it seems to be due to the fact that Vite uses @babel/standalone, which runs Browserslist in browser mode, rather than in node mode. You can see that in node mode, getStat() checks for the presence of process.env.BROWSERSLIST_STATS, a 'browserslist-stats.json' file (which I believe is what we need!), whereas the browser mode version only getStats() from opts - and as Vite and @babel/standalone aren't passing any opts.stats onto browserslist, and so the custom stats in browserslist-stats.json aren't picked up.

Reproduction

https://stackblitz.com/edit/vitejs-vite-anpxkm?file=vite.config.ts

Steps to reproduce

Simply run npm run build and see the error, even though there is a totally valid browserslist-stats.json in the project root.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @vitejs/plugin-legacy: ^2.2.0 => 2.2.0 
    vite: ^3.1.6 => 3.1.8 

Used Package Manager

npm

Logs

Click to expand!
[vite:legacy-post-process] [BABEL] unknown file: Custom usage statistics was not provided (While processing: "base$1")
error during build:
BrowserslistError: [BABEL] unknown file: Custom usage statistics was not provided (While processing: "base$1")
    at Function.coverQuery (/usr/src/app/node_modules/@babel/standalone/babel.js:67738:17)
    at /usr/src/app/node_modules/@babel/standalone/babel.js:67492:31
    at Array.reduce (<anonymous>)
    at resolve$2 (/usr/src/app/node_modules/@babel/standalone/babel.js:67486:38)
    at browserslist (/usr/src/app/node_modules/@babel/standalone/babel.js:67591:23)
    at resolveTargets$1 (/usr/src/app/node_modules/@babel/standalone/babel.js:69305:20)
    at getTargets$2 (/usr/src/app/node_modules/@babel/standalone/babel.js:69358:27)
    at getLocalTargets (/usr/src/app/node_modules/@babel/standalone/babel.js:135279:12)
    at /usr/src/app/node_modules/@babel/standalone/babel.js:135337:17
    at /usr/src/app/node_modules/@babel/standalone/babel.js:76225:14
    at sync (/usr/src/app/node_modules/@babel/standalone/babel.js:63066:25)
    at sync (/usr/src/app/node_modules/@babel/standalone/babel.js:62831:22)
    at _callee$ (/usr/src/app/node_modules/@babel/standalone/babel.js:62890:26)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:108:26)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at maybeInvokeDelegate (/usr/src/app/node_modules/@babel/standalone/babel.js:210:20)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:95:36)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at maybeInvokeDelegate (/usr/src/app/node_modules/@babel/standalone/babel.js:210:20)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:95:36)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at evaluateSync (/usr/src/app/node_modules/@babel/standalone/babel.js:62941:30)
    at Function.sync (/usr/src/app/node_modules/@babel/standalone/babel.js:62722:16)
    at sync (/usr/src/app/node_modules/@babel/standalone/babel.js:63117:27)
    at sync (/usr/src/app/node_modules/@babel/standalone/babel.js:62831:22)
    at _callee$ (/usr/src/app/node_modules/@babel/standalone/babel.js:62890:26)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:108:26)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at maybeInvokeDelegate (/usr/src/app/node_modules/@babel/standalone/babel.js:210:20)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:95:36)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at maybeInvokeDelegate (/usr/src/app/node_modules/@babel/standalone/babel.js:210:20)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:95:36)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at maybeInvokeDelegate (/usr/src/app/node_modules/@babel/standalone/babel.js:210:20)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:95:36)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at maybeInvokeDelegate (/usr/src/app/node_modules/@babel/standalone/babel.js:210:20)
    at Generator._invoke (/usr/src/app/node_modules/@babel/standalone/babel.js:95:36)
    at Generator.next (/usr/src/app/node_modules/@babel/standalone/babel.js:159:23)
    at tryCatch (/usr/src/app/node_modules/@babel/standalone/babel.js:128:19)
    at maybeInvokeDelegate (/usr/src/app/node_modules/@babel/standalone/babel.js:210:20)

Validations

@sapphi-red
Copy link
Member

Thanks for the findings!
Closing as a duplicate of #2476 (I've put a link to your findings there)

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2022
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Nov 14, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants