question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Set "browserslist": ["last 1 chrome version"] in package.json of generated project (may need to delete node_modules/.cache if it exists)
  2. Create a React component that is used in a .mdx document
  3. Use optional chaining operator within the React component
  4. Use start or build 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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
ianschmitzcommented, Jun 11, 2020
2reactions
slorbercommented, Jun 9, 2020

probably need to wait as there are pending changes to babel config here: https://github.com/facebook/docusaurus/pull/2903/files

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found