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

ChunkAssetPlugin injection breaks imported web workers #8389

Closed
6 of 7 tasks
elilambnz opened this issue Nov 29, 2022 · 4 comments
Closed
6 of 7 tasks

ChunkAssetPlugin injection breaks imported web workers #8389

elilambnz opened this issue Nov 29, 2022 · 4 comments
Labels
external This issue is caused by an external dependency and not Docusaurus.

Comments

@elilambnz
Copy link

elilambnz commented Nov 29, 2022

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

I'm developing a package that uses web workers. Everything works fine in a development build of docusaurus, however during build time the following lines are injected by ChunkAssetPlugin:

__webpack_require__.gca = function(e) {
    return e = {}[e] || e,
    __webpack_require__.p + __webpack_require__.u(e)
}

This is breaking the functionality of the web workers and produces the following error:

Uncaught ReferenceError: __webpack_require__ is not defined

Is there anyway to either prevent this behaviour for certain files, or structure my package in such a way that it is ignored by the webpack build step?

Reproducible demo

https://stackblitz.com/edit/github-1neuf8?file=src/pages/index.js

Steps to reproduce

  1. Open the reproducible demo
  2. Start docusaurus, there are no errors
  3. Create a build and then serve docusaurus
  4. The error occurs

Expected behavior

Docusaurus should ignore these files in the imported package, resulting in expected behaviour as observed with a development build.

Actual behavior

The error detailed in the description occurs. It is worth noting that the package works as expected with a clean build of Nextjs.

Your environment

  • Docusaurus version used: 2.2.0

Self-service

  • I'd be willing to fix this bug myself.
@elilambnz elilambnz 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 Nov 29, 2022
@Josh-Cena
Copy link
Collaborator

It's too hard for me to understand what's going on. A repro is appreciated—"install the npm package in question", I have zero idea how to reproduce that.

@elilambnz
Copy link
Author

It's too hard for me to understand what's going on. A repro is appreciated—"install the npm package in question", I have zero idea how to reproduce that.

@Josh-Cena my apologies, I've amended the issue with a reproducible demo and steps to reproduce. The error can be seen in the console after running the serve command.

Please let me know if there is any more info I can provide to help address this.

@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Nov 30, 2022
@slorber
Copy link
Collaborator

slorber commented Nov 30, 2022

Thanks

Your repro is using react-py, which uses Service Worker lib comlinks + pyodide:
https://github.com/elilambnz/react-py

This puts the burden on me to understand the implementation details of your lib and how Docusaurus can mess things up here (if it is even our fault in the first place? 🤷‍♂️ ).

That would be convenient to create a repro using the full setup "inlined", ie removing the react-py deps and comlinks, with a vanilla JS SW setup.

I would also suggest that you post the minimalist SW output that Docusaurus builds: what is the output, and what do you expect as an output?

Maybe you can tweak the SW output until it works and tell us what unlocks you, so that we can see how we can make the JS output you expect a reality?

I suspect adding window.__webpack_require__ = {} to the js file could make it work. __webpack_require__.gca doesn't seem to even be called in that script


This is likely a time-consuming bug (if it is one) for little ROI for our other users so I'm asking you to invest your time to help us here.

@Josh-Cena Josh-Cena added the status: needs more information There is not enough information to take action on the issue. label Dec 2, 2022
@elilambnz
Copy link
Author

@slorber thanks for your feedback and suggestions to resolve this error. Unfortunately, adding the monkey patch for __webpack_require__ didn't resolve the issue. However, I did find a related issue.

Adding the following config to Docusaurus does resolve this issue, although it's not the best solution:

plugins: [
  async function disableUsedExports() {
    return {
      name: "disable-used-exports",
      configureWebpack() {
        return {
          optimization: {
            usedExports: false,
          },
        };
      },
    };
  },
]

Because this issue may not be directly related to the ChunkAssetPlugin, the title may be misleading.

@Josh-Cena Josh-Cena added external This issue is caused by an external dependency and not Docusaurus. and removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs more information There is not enough information to take action on the issue. labels Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This issue is caused by an external dependency and not Docusaurus.
Projects
None yet
Development

No branches or pull requests

3 participants