UPD for everyone who will find this issue. For fix this error acornjs/acorn#891 and acornjs/acorn#890 must be merged.
UPD2 we all awaiting while estree/estree/pull/204 will be merged
UPD3 fix for optional chaining landed into acorn 7.3.0 but webpack@4 uses acorn 6.x. so fix of this issue will be in webpack@5: #10227 (comment)
Temporary fixes
For Babel
Add @babel/plugin-proposal-optional-chaining and @babel/plugin-proposal-nullish-coalescing-operator plugins in your config
For Typescript
Do not upgrade to version 3.8 or set compiler option target to es2019
Yarn/NPM level
See the #10227 (comment)
Do you want to request a feature or report a bug?
I don't know is it a bug or feature
What is the current behavior?
Get error "Unecpected token"
What is the expected behavior?
Build bundle successfull
Description
When I set in tsconfig.json target: "ESNext" TS keeps my code with optional chaining (and nullish coalescing) as is. But I've got an error
Module parse failed: Unexpected token (2:10)
File was processed with these loaders:
* ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
| var a = { b: 2 };
> var c = a?.b;
I made a minimum reproduce repo inoyakaigor/webpack-typescript-optional-chaining
How I can avoid this error?
UPD for everyone who will find this issue. For fix this error acornjs/acorn#891 and acornjs/acorn#890 must be merged.UPD2 we all awaiting while estree/estree/pull/204 will be merged
UPD3 fix for optional chaining landed into acorn 7.3.0 but webpack@4 uses acorn 6.x. so fix of this issue will be in webpack@5: #10227 (comment)
Temporary fixes
For Babel
Add
@babel/plugin-proposal-optional-chainingand@babel/plugin-proposal-nullish-coalescing-operatorplugins in your configFor Typescript
Do not upgrade to version 3.8 or set compiler option
targettoes2019Yarn/NPM level
See the #10227 (comment)
Do you want to request a feature or report a bug?
I don't know is it a bug or feature
What is the current behavior?
Get error "Unecpected token"
What is the expected behavior?
Build bundle successfull
Description
When I set in
tsconfig.jsontarget: "ESNext"TS keeps my code with optional chaining (and nullish coalescing) as is. But I've got an errorI made a minimum reproduce repo inoyakaigor/webpack-typescript-optional-chaining
How I can avoid this error?