[9.5.4-canary.20] default loader doesn't transpile nullish coalescing and optional chaining
See original GitHub issueBug report
Describe the bug
Loader next-babel-loader
doesn’t transpile nullish coalescing operator and optional chaining on canary
To Reproduce
Repository: next.js-bug-nullish-coalescing Steps to reproduce the behavior:
- Go to http://localhost:3000
- See error
- Go to http://localhost:3000/about
- See error
Expected behavior
Don’t see the errors.
Screenshots
System information
- OS: macOS
- Browser (if applies): chrome
- Version of Next.js:
9.5.4-canary.20
- Version of Node.js:
14.2.0
Additional context
Works with 9.5.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Webpack cant compile ts 3.7 (Optional Chaining, Nullish ...
I'm using babel-loader. And I correctly put the 2 plugins in the file because these syntax are working for my own files. But...
Read more >babel/plugin-proposal-nullish-coalescing-operator
boolean , defaults to false . When true , this transform will pretend document.all does not exist, and perform loose equality checks with...
Read more >Optional Chaining and Nullish coalescing explained - YouTube
Optional chaining and nullish coalescing are 2 new JavaScript features which are ready to land in major browsers by 2020.
Read more >@next/mdx: Versions | Openbase
Fix replaceAll usage in font loader: #42550; Fix default value handling for CNA in CI: # ... refactor(build): no force transpile optional chaining:...
Read more >Addy Osmani on Twitter: "Optional Chaining & Nullish ...
Optional Chaining & Nullish Coalescing are coming to JavaScript! They're short, readable and are both available to try in Chrome Canary ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is thrown since
preset-env
skipsoptional-chaining
. It is intended because the environment supports optional chaining natively, (e.g. last 2 chrome). However in order to parseimport
andexport
and evaluation expressions likeprocess.env.NODE_ENV
, webpack will parse the Babel transpiled code viaacorn
. Sinceoptional-chaining
is skipped, the error is thus thrown fromacorn
. Webpack@4 usesacorn@6
which does not support optional chaining.I have open a PR to bump acorn to 8.0.1 in webpack 4: https://github.com/webpack/webpack/pull/11550.
Before it is merged. Choose one of the workaround according to your risk preference.
Workaround a): update webpack to 5.0.0-rc.1 Workaround b): resolve
acorn
to 8.0.1, checknpm-force-resolutions
or yarn resolutions Workaround c): update next.js to 9.5.4-canary.23 Workaround d): add the following to the"include"
config of"@babel/preset-env"
Workaround e): remove all ES2020 features from your source code, wait until you are comfortable to update deps.
Hmm, I still have this issue with v14.12.0 and Typescript 4.0.3 after https://github.com/vercel/next.js/pull/17429 was merged.Edit:
This was missing. Works! 😃