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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional chaining breaks build when targeting modern browsers #2908

Closed
ianschmitz opened this issue Jun 8, 2020 · 6 comments 路 Fixed by #3007
Closed

Optional chaining breaks build when targeting modern browsers #2908

ianschmitz opened this issue Jun 8, 2020 · 6 comments 路 Fixed by #3007
Labels
bug An error in the Docusaurus core causing instability or issues with its execution mlh Major League Hacking Fellowship

Comments

@ianschmitz
Copy link

ianschmitz commented Jun 8, 2020

馃悰 Bug Report

Using the optional chaining operator causes the build to fail when targeting modern browsers through browserslist. See facebook/create-react-app#8526 for the same issue we ran into in CRA.

Have you read the Contributing Guidelines on issues?

Yes.

To Reproduce

  1. Set "browserslist": ["last 1 chrome version"] in package.json of generated project (may need to delete node_modules/.cache if it exists)
  2. Create a React component that is used in a .mdx document
  3. Use optional chaining operator within the React component
  4. Use start or build script and observe error similar to following:

Expected behavior

Build succeeds.

Actual Behavior

Module parse failed: Unexpected token (12:111)
File was processed with these loaders:
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| useEffect(()=>{if(!messagingJson){return;}// Decode entities in the URL
> const hash=window.decodeURIComponent(window.location.hash);if(hash){document.getElementById(hash.substring(1))?.scrollIntoView();}},[messagingJson]);return messagingJson?/*#__PURE__*/React.createElement(MessagingContent,{schema:messagingJson,type:type}):/*#__PURE__*/React.createElement("div",null,"Loading...");}
 @ ./src/components/ViewerMessaging/index.ts 1:0-39 1:0-39
 @ ./docs/mobile/api-commands-operations-events.mdx
 @ ./.docusaurus/registry.js
 @ ./node_modules/@docusaurus/core/lib/client/exports/ComponentCreator.js
 @ ./.docusaurus/routes.js
 @ ./node_modules/@docusaurus/core/lib/client/clientEntry.js
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./node_modules/@docusaurus/core/lib/client/clientEntry.js

Your Environment

  • Docusaurus version used: 2.0.0-alpha.56
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Chrome 83
  • Operating system and version (desktop or mobile): Ubuntu 20.04
@ianschmitz ianschmitz added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Jun 8, 2020
ianschmitz added a commit to geocortex/dev-center that referenced this issue Jun 8, 2020
@slorber
Copy link
Collaborator

slorber commented Jun 9, 2020

Thanks for reporting.

Can confirm.

Easier steps to reproduce directly on D2 website, for a contributor:

"browserslist": ["last 1 chrome version"]

rm -rf website/node_modules/.cache

yarn start:v2

The classic theme that we use already uses nullish coalescing / optional chaining

image

@slorber slorber added mlh Major League Hacking Fellowship and removed status: needs triage This issue has not been triaged by maintainers labels Jun 9, 2020
@slorber
Copy link
Collaborator

slorber commented Jun 9, 2020

@yangshun I added MLH tag, it's probably just adding the 2 plugins in the webpack config.

@slorber
Copy link
Collaborator

slorber commented Jun 9, 2020

probably need to wait as there are pending changes to babel config here: https://github.com/facebook/docusaurus/pull/2903/files

@ianschmitz
Copy link
Author

ianschmitz commented Jun 11, 2020

This may be fixed upstream: webpack/webpack#10227 (comment).

Edit: Doh, looks like webpack 4 is still referencing acorn 6: https://github.com/webpack/webpack/blob/dfd20210c9441c309859d29d3b256474ae5101e5/package.json#L12.

@slorber
Copy link
Collaborator

slorber commented Jun 17, 2020

fixed by #2951

@slorber slorber closed this as completed Jun 17, 2020
@slorber
Copy link
Collaborator

slorber commented Jun 18, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution mlh Major League Hacking Fellowship
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants