Skip to content
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

Module parse failed on optional chaining #871

Closed
paztis opened this issue Oct 5, 2020 · 4 comments
Closed

Module parse failed on optional chaining #871

paztis opened this issue Oct 5, 2020 · 4 comments

Comments

@paztis
Copy link

paztis commented Oct 5, 2020

BEFORE YOU SUBMIT please read the following:

Delete what isn't applicable below
I'm submitting a bug report

Webpack Version:
4.44.2

Babel Core Version:
7.11.6

Babel Loader Version:
8.1.0

Please tell us about your environment:
OSX 10.15

Current behavior:
I just try to remove the @babel/plugin-proposal-optional-chaining plugin from my configuration as it is natively supported (and managed through @babel/preset-env)

Compilation works correctly using pure babel
Compilation is failing with babel-loader

ERROR in ./src/pages/design/DesignPage.template.tsx 18:36
Module parse failed: Unexpected token (18:36)
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.
|     viewId
|   } = props;
>   const topMessage = props.messages?.[0];
|   const isWarningMessage = topMessage && (topMessage.severity === 'CRITICAL' || topMessage.severity === 'ERROR' || topMessage.severity === 'WARNING');
|   return /*#__PURE__*/React.createElement(Container, {
 @ ./src/pages/design/DesignPage.component.tsx 16:0-55 150:40-58
 @ ./src/application/App.tsx
 @ ./src/index.tsx

Expected/desired behavior:
As it works natively with browser, it must be supported as non transpiled.
Babel (through @babel/preset-env) and browerslist do their job.
But babel-loader here is blocking

@paztis
Copy link
Author

paztis commented Oct 5, 2020

ok understand it is a problem of acorn version
Webpack 4.44 still point to 6.x, while optional chaining is only supported in 7.x...
Hope it can be resolved

@JLHwung
Copy link
Contributor

JLHwung commented Oct 5, 2020

This is an upstream webpack issue: webpack/webpack#11186 It is fixed in Webpack 5 however it can not backport to webpack 4 since Acorn 7 introduces new AST for import() - webpack relies on the AST to do code splitting.

@egemon
Copy link

egemon commented Jan 6, 2021

For those who also don't find here the solution - here is good explanation of what is going on
nuxt/nuxt#7722 (comment)

dodoongtak added a commit to dodoongtak/react-week2-assignment-2 that referenced this issue Jan 29, 2021
Optional Chaining doesn't working in current webpack version.

The Issue Reference :
babel/babel-loader#871
@SarjuHansaliya
Copy link

For those who are using webpack < 5 and nothing is working then try this it worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants