You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
[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)
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
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 likecovers 95% in my stats
to my plugin-legacytargets
, I should be able to build for production successfully.Instead build fails with:
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 ofprocess.env.BROWSERSLIST_STATS
, a'browserslist-stats.json'
file (which I believe is what we need!), whereas the browser mode version only getStats() fromopts
- and as Vite and@babel/standalone
aren't passing anyopts.stats
onto browserslist, and so the custom stats inbrowserslist-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 validbrowserslist-stats.json
in the project root.System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: