Can't use optional chaining operator
See original GitHub issueWhen 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:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top 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 >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
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 😃
@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 ?