Optional chaining breaks build when targeting modern browsers
See original GitHub issue🐛 Bug Report
Using the optional chaining operator causes the build to fail when targeting modern browsers through browserslist
. See https://github.com/facebook/create-react-app/pull/8526 for the same issue we ran into in CRA.
Have you read the Contributing Guidelines on issues?
Yes.
To Reproduce
- Set
"browserslist": ["last 1 chrome version"]
in package.json of generated project (may need to deletenode_modules/.cache
if it exists) - Create a React component that is used in a
.mdx
document - Use optional chaining operator within the React component
- Use
start
orbuild
script and observe error similar to following:
Expected behavior
Build succeeds.
Actual Behavior
Module parse failed: Unexpected token (12:111)
File was processed with these loaders:
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| useEffect(()=>{if(!messagingJson){return;}// Decode entities in the URL
> const hash=window.decodeURIComponent(window.location.hash);if(hash){document.getElementById(hash.substring(1))?.scrollIntoView();}},[messagingJson]);return messagingJson?/*#__PURE__*/React.createElement(MessagingContent,{schema:messagingJson,type:type}):/*#__PURE__*/React.createElement("div",null,"Loading...");}
@ ./src/components/ViewerMessaging/index.ts 1:0-39 1:0-39
@ ./docs/mobile/api-commands-operations-events.mdx
@ ./.docusaurus/registry.js
@ ./node_modules/@docusaurus/core/lib/client/exports/ComponentCreator.js
@ ./.docusaurus/routes.js
@ ./node_modules/@docusaurus/core/lib/client/clientEntry.js
@ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./node_modules/@docusaurus/core/lib/client/clientEntry.js
Your Environment
- Docusaurus version used: 2.0.0-alpha.56
- Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Chrome 83
- Operating system and version (desktop or mobile): Ubuntu 20.04
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Devon Govett ar Twitter: "Unbelievable! Optional chaining and ...
Optional chaining and nullish coalescing are supported in all modern browsers, representing over 92% of users globally. But some build tools ...
Read more >Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The optional chaining ( ?. ) operator accesses an object's property or calls a function. If the object accessed or function called is ......
Read more >Optional chaining trap ! - DEV Community
It's going to be really verbose in your bundles. The transformation made by babel in the state does not at all share the...
Read more >The optional chaining operator, “modern ... - Hacker News
There's an argument to be made for a tradeoff between legacy device support and cleaning up cruft, but the part that stands out...
Read more >The optional chaining operator, “modern” browsers ... - Reddit
That's what Babel is for - most new JS features can be easily mapped to some other JS construct that works on all...
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
This may be fixed upstream: https://github.com/webpack/webpack/issues/10227#issuecomment-642536906.
Edit: Doh, looks like webpack 4 is still referencing acorn 6: https://github.com/webpack/webpack/blob/dfd20210c9441c309859d29d3b256474ae5101e5/package.json#L12.
probably need to wait as there are pending changes to babel config here: https://github.com/facebook/docusaurus/pull/2903/files