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

__webpack_require__(...) is not a function #557

Closed
polisen opened this issue Jul 22, 2021 · 3 comments
Closed

__webpack_require__(...) is not a function #557

polisen opened this issue Jul 22, 2021 · 3 comments

Comments

@polisen
Copy link

polisen commented Jul 22, 2021

Hey - I'm using customize-cra and react-app-rewired to override the webpack config usually abstracted away in a create-react-app.

I'm importing the random-int package to the worker file - which is the import that fails.

config-overrides.js

const { override, addWebpackModuleRule, babelInclude } = require("customize-cra");
const path = require('path')
module.exports = override(
  addWebpackModuleRule({
    test: /\.worker\.(js|ts)$/i,
    use: [
      {
        loader: "comlink-loader",
        options: {
          singleton: true,
        },
      },
    ],
  })
);

This is the correct syntax - but now it complains about that webpack doesn't have a require function - which is to be expected. Supposedly something wasn't transpiled by babel but I can't figure out where to even begin.

Do you geniuses have any idea?

@dawnmist
Copy link
Collaborator

I haven't seen the comlink-loader used before for workers. Reading their issues list, there's a couple of potential issues that may help.

  1. Webpack 5 compatibility: the project hasn't been updated since Jan 2020, and there is an open issue for changes required to make it compatible with Webpack 5. For them it was complaining about __webpack_exports__ rather than the require, so their solution might not help you but it still would be worth looking at. There is one option people were able to set to get it working:
    support for webpack 5 GoogleChromeLabs/comlink-loader#34

  2. Another person found that the singleton mode wouldn't work without adding a babel loader portion to the use array as well. If the Webpack 5 issue's option doesn't help, the addition of babel-loader to the list of use loaders for the worker might:
    Not generating a web worker script GoogleChromeLabs/comlink-loader#36

Failing those, are you able to provide an example repository that has this issue so that I can trace through what is happening during compilation?

@jobh
Copy link

jobh commented Sep 23, 2021

FWIW: I had a similar problem. Two issues in my case:

@timarney
Copy link
Owner

Closing this given no recent activity.

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