Next.js doesn't respect Browserslist #12826
-
Out of the box, defining a browserslist query the standard ways in your project (e.g. via a I see people hardcoding a query into the Next.js Babel preset config, like this: But that is a poor solution as Browserslist won't find the query for other tools (e.g. ESLint plugins). I'm not even sure what it does, since Next.js customises the Ideally we should be able to specify our Browserslist queries the standard ways, and Next.js will never add targets on top of it - only intersect that query and possibly reduce the number of targets as a result for the special builds. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 10 replies
-
https://babeljs.io/docs/en/babel-preset-env#browserslist-integration I tried this Babel config: {
"presets": [
[
"next/babel",
{
"preset-env": {
"targets": null
}
}
]
]
} And it seems to cause the |
Beta Was this translation helpful? Give feedback.
-
next.js/packages/next/build/babel/preset.ts Lines 91 to 97 in f658b76
It seems we can use |
Beta Was this translation helpful? Give feedback.
-
Is there a more official solution to this issue yet? Here's what we're doing, but it feels extremely brittle since Next.js can change how it uses const { readFileSync } = require('fs')
const { join } = require('path')
const browsersList = readFileSync(
join(__dirname, '.browserslistrc'), 'utf8'
).split('\n')
// Next.js should use the .browserslistrc file
module.exports = {
presets: [
[
"next/babel",
{
"preset-env": {
targets: browsersList
}
}
]
]
} |
Beta Was this translation helpful? Give feedback.
-
Guys, can you please all upvote this discussion by pressing the arrow at the top left of the discussion (on desktop): Right now, 18 people have thumbed it but no one has actually upvoted the discussion to bring it to the attention of the wider community or Next.js team: Also a side note, the GitHub design is a bit stupid I can only add a comment to this "discussion" by pressing a button called "Answer": |
Beta Was this translation helpful? Give feedback.
-
I think the issue I've just filed might be related to this discussion: #23658. Next.js' autoprefixer setup is not adding the vendor prefixes you'd expect based on the browserslist in package.json (see issue for details). |
Beta Was this translation helpful? Give feedback.
-
I think it is already possible like this in
Or am I missing something? See also the docs here: https://nextjs.org/docs/advanced-features/customizing-babel-config I have not checked if it works because I did it just now, but I feel like the time to spin up the dev server is faster, so I think it worked. |
Beta Was this translation helpful? Give feedback.
-
Seems now Next.js (Babel) will respect Browserslist. |
Beta Was this translation helpful? Give feedback.
-
Does anyone have an idea on how this is handled with SWC? The browserslist key in package.json seems to have no effect and neither does having a custom config in .swcrc as metioned in the swc docs… |
Beta Was this translation helpful? Give feedback.
-
You can now add browserslist when enabling an experimental flag: #33227 (comment) |
Beta Was this translation helpful? Give feedback.
-
Did someone find an actually solution? I have next 12.3 with swc with styled-jsx and somehow it works only on the latest versions of browsers (in all platform) and in other versions there are style breaks |
Beta Was this translation helpful? Give feedback.
You can now add browserslist when enabling an experimental flag: #33227 (comment)