Nullish assignment (??=) not working in new project
See original GitHub issueTypescript 4 supports the nullish assignment operator (??=). Creating a new Typescript project with CRA 4 supports this operator in the editor, but when running yarn start
it gives a Webpack parsing error.
I asked on SO here and they confirm the bug and suggest it requires a Babel upgrade.
Steps to reproduce:
- Create a new project with Typescript
- Add the following lines into App.tsx:
const test = { a: 1 };
test.a ??= 2;
- Run
yarn start
Expected result: App starts
Actual result:
Module parse failed: Unexpected token (14:10)
File was processed with these loaders:
* ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:42
- Comments:24
Top Results From Across the Web
Typescript 4 nullish assignment (??=) not working in new CRA ...
To reproduce the problem I just create a new app with CRA with Typescript support. Then just add the following lines to App....
Read more >Nullish coalescing assignment (??=) - JavaScript | MDN
No assignment is performed if the left-hand side is not nullish, due to short-circuiting of the nullish coalescing operator.
Read more >Logical nullish Assignment ??= in JavaScript - GeeksforGeeks
This is a new operator introduced by javascript. This operator is represented by x ??= y and it is called Logical nullish assignment...
Read more >Logical nullish assignment (??=) - JavaScript
Short circuit means that the expr part above is not evaluated, hence any side effects of doing so do not take effect (e.g.,...
Read more >Nullish coalescing operator '??' - The Modern JavaScript Tutorial
The nullish coalescing operator isn't anything completely new. It's just a nice syntax ... Here's the example with user assigned to a name:....
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 is possibly now resolved.
The irony of
Nullish Assignment
being supported in every browser, but breaking via the very thing that’s meant to make future proofing codebases easier.