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.

Nullish assignment (??=) not working in new project

See original GitHub issue

Typescript 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:

  1. Create a new project with Typescript
  2. Add the following lines into App.tsx:
const test = { a: 1 };
test.a ??= 2;
  1. 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:open
  • Created 3 years ago
  • Reactions:42
  • Comments:24

github_iconTop GitHub Comments

21reactions
razzfoxcommented, Dec 11, 2020

This is possibly now resolved.

18reactions
kellengreencommented, Oct 21, 2021

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.

Read more comments on GitHub >

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

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