next.js: nextjs 13.4.13 is not transpiling code to browser old versions even with browserslist option in package.json
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 20.6.0: Thu Mar 9 20:39:26 PST 2023; root:xnu-7195.141.49.700.6~1/RELEASE_X86_64
Binaries:
Node: 16.14.2
npm: 8.5.0
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 13.4.14-canary.1
eslint-config-next: 13.4.13
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.6
Next.js Config:
output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
https://github.com/yanv1991/test-2017
To Reproduce
run yarn build
and then yarn start
note: webpack custom config was added to disable minimizer
look for the .next
folder inside the main-xxxxx
file you will see non es5 syntax like:
Describe the Bug
when adding browserslist
option in package.json with a value like this: >0.3%, defaults, supports es5
the next bundle is still generating modern syntax.
Expected Behavior
if browserslist with es5 target is configured the bundle should not generate modern syntax like let, const
…
Which browser are you using? (if relevant)
Chrome 48.0.2527.0
How are you deploying your application? (if relevant)
local
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 3
- Comments: 19 (1 by maintainers)
I also noticed an extremely strange effect. If I remove browserslist from package.json (I think that the default settings specified in the documentation should be used), then in the chunk file “.next\static\chunks\app_not-found-[hash].js” in default next.js 14 project I see let variables. If I add browserslist with “last 2 Chrome versions”, then in the same chunk I see var variables 👀. In general, there is a feeling that no matter what target you set in browserslist and no matter what experimental settings you use (for example, from this issue - https://github.com/vercel/next.js/issues/12557), the size of the client bundle does not change in any way (no difference is observed in either the CLI report after the ‘build’ command or in the ‘next/bundle-analyzer’ report. sometimes by 1-2 kb, but even then rarely). It’s quite a frustrating experience. I don’t want to sound rude (and I apologize if it sounds like that), but I see only 2 possible options here:
@woshiqiang1 The easiest way to find with package it was is: next.config.js
Sometimes it might be a sub dependency of a dependency. When you do like that you still have the comments left with package names and discovered that sub packages contained ES6 code. Than I just added them too.
I got this working for both babel and swc. Don’t forget to set the
browserslist
inpackage.json
.I also ran into issues after upgrading to Next 13.5.2, the build would generate non-ES5 syntax (that I check with the es-check package
es-check es5 '.next/static/chunks/main-*.js'
)I also found that the output chunk contained some Next.js router code that had
let
.I also fixed it by adding
next
to mytranspilePackages
config.@EloB Thanks I try the way you said above and it works !! but it’s really not a very elegant and convenient way hope Next.js optimize this DX someday.
hey @EloB I tried adding
next
in the transpile packages option and it worked, however not sure if this is a clean solution 🤔 https://github.com/yanv1991/test-2017/blob/32bb16a17fff9e12b488b33dbad48b18a9bf0f88/next.config.js#L13@EloB yes the repo that I posted here is a app generated using the next-create-app CLI, without any dependency and the error looks like is inside nextjs core