New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected token error at code with optional chaining when using Typescript #10227
Comments
It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I'm closing this. Please either update the issue with the template and reopen, or open a new issue. |
@evilebottnawi Closing the issue because I removed the template looks like excessive bureaucracy. However, I updated the description. |
@evilebottnawi looks like @inoyakaigor updated the description and also provided a reproduction repo. I think we're hitting this same issue with optional chaining. |
For others that stumble on this issue, it looks like we're waiting on acornjs/acorn#891 and acornjs/acorn#890 before we stop transpiling this syntax via babel/tsc. |
it looks like the mentioned issues on acorn have been merged, any news? |
@evilebottnawi Can we reopen this issue? Since this is a unresolved problem, it will help people find answers and let people track the progress. |
Good news everyone! Acorn 7.3.0 with optional chaining support just released 2 hours ago! https://github.com/acornjs/acorn/blob/master/acorn/CHANGELOG.md |
Unfortunately webpack 4 uses acorn 6.x - not sure if we'll get this before webpack 5. Fingers crossed! |
Yes, it will be part of webpack@5 |
as a temporary solution;
{
...
"resolutions": {
"acorn": "npm:acorn-with-stage3"
},
"dependencies": {
|
this change fixes optional chaining issue which was fixed in acord@v8 and that is fixed in webpack 5 reference link: webpack/webpack#10227 (comment)
this change fixes optional chaining issue which was fixed in acord@v8 and that is fixed in webpack 5 reference link: webpack/webpack#10227 (comment)
FYI to others that are considering using the |
Sets The compilation target of the repo to 2019 for webpack 4 compat webpack/webpack#10227 which does not support optional chaining without extra babel loader transpilation.
webpack did not recognize optional chaining token (?.) webpack/webpack#10227 (comment)
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 configFor Typescript
Do not upgrade to version 3.8 or set compiler option
target
toes2019
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 errorI made a minimum reproduce repo inoyakaigor/webpack-typescript-optional-chaining
How I can avoid this error?
The text was updated successfully, but these errors were encountered: