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.

Can't use optional chaining operator

See original GitHub issue

When using the ?. operator, as in item?.status, yarn start cannot compile the code:

ERROR in ./src/selectors/sources.js 7:155
Module parse failed: Unexpected token (7:155)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import { getSelectedSourceTabFile } from "./url-state";
| export const getSources = state => state.sources;
> export const getSelectedSourceTabSource = createSelector(getSources, getSelectedSourceTabFile, (sources, file) => sources.find(item => item.file === file)?.status);
 @ ./src/selectors/index.js 13:0-26 13:0-26 23:0-37 34:2-9
 @ ./src/utils/window-console.js
 @ ./src/index.js
 @ multi ./src/index

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
julienwcommented, Nov 15, 2021

I believe the problem is with webpack 4. Webpack 5 supports this operator properly (because it uses a newer version of acorn, which parses this syntax). So to support this, we need to upgrade to webpack 5 (#3124). But before that we have to change our service worker implementation (#3272).

Soooo that’s a little bit of work 😃

0reactions
VishakhBhatcommented, Nov 14, 2021

@julienw the PR build failed because of the optional chaining character, but the flow(yarn flow) is fine.

Does that mean we have issue here ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Cannot use optional chaining on non-optional value
I have a swift struct containing an array: struct S { let a: [Int] }. and an optional value of S. var s:...
Read more >
What is wrong with optional chaining and how to fix it - DEV ...
The operator tries to address issues of previously used && . This article tries to make a point that JS has Nullable, and...
Read more >
Can't implement simple optional chaining - Stack Overflow
What I want is for the items to ONLY be changed IF the item is defined/exists; if not/is undefined, I want the item...
Read more >
Optional chaining '?.' - The Modern JavaScript Tutorial
The optional chaining ?. is a safe way to access nested object properties, even if an intermediate property doesn't exist.
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