Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

Webpack 5: ParserHelpers.addParsedVariableToModule is not a function #88

Open

Description

@balloob

Using Webpack 5 beta 25 (latest as of today) and worker plugin 5.0.0.

Initially reported at #84 (comment) but realized should have opened an issue.

TypeError: ParserHelpers.addParsedVariableToModule is not a function
    at /home/paulus/dev/hass/frontend/node_modules/worker-plugin/dist/worker-plugin.js:120:25
    at Hook.eval [as call] (eval at create (/home/paulus/dev/hass/frontend/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:5:16)
    at JavascriptParser.callHooksForInfoWithFallback (/home/paulus/dev/hass/frontend/node_modules/webpack/lib/javascript/JavascriptParser.js:2784:24)
    at JavascriptParser.callHooksForExpression (/home/paulus/dev/hass/frontend/node_modules/webpack/lib/javascript/JavascriptParser.js:2666:16)
    at JavascriptParser.walkNewExpression (/home/paulus/dev/hass/frontend/node_modules/webpack/lib/javascript/JavascriptParser.js:2379:23)
    at JavascriptParser.walkExpression (/home/paulus/dev/hass/frontend/node_modules/webpack/lib/javascript/JavascriptParser.js:2131:10)
    at JavascriptParser.walkExpressions (/home/paulus/dev/hass/frontend/node_modules/webpack/lib/javascript/JavascriptParser.js:2078:10)
    at /home/paulus/dev/hass/frontend/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js:136:22
    at Hook.eval [as call] (eval at create (/home/paulus/dev/hass/frontend/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:5:16)
    at JavascriptParser.callHooksForInfoWithFallback (/home/paulus/dev/hass/frontend/node_modules/webpack/lib/javascript/JavascriptParser.js:2768:26)

Webpack 5 source for ParserHelpers does indeed not contain that function. Searching the Webpack 5 codebase also doesn't find it 🤔

I tried using the Webpack 4 definition on Webpack 5 does bundle, but doesn't work:

ReferenceError: __webpack__worker__0 is not defined

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "renderMarkdown": () => /* binding */ renderMarkdown
/* harmony export */ });
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! comlink */ "./node_modules/comlink/dist/esm/comlink.mjs");

let worker;
const renderMarkdown = async (content, markedOptions, hassOptions) => {
  if (!worker) {
    worker = (0,comlink__WEBPACK_IMPORTED_MODULE_0__.wrap)(new Worker(__webpack__worker__0, undefined));
  }

  return await worker.renderMarkdown(content, markedOptions, hassOptions);
};//# sourceURL=[module]

original source of above code (which works on webpack 4)

Activity

  1. balloob commented on Aug 12, 2020

    @balloob
    Author

    The function was removed in webpack/webpack#7781 (commit webpack/webpack@5553166)

  2. developit commented on Sep 8, 2020

    @developit
    Contributor

    Yikes - I didn't know about this removal, thanks for looking into this.

    I believe the following should work as a replacement for the usage, to support both Webpack 4 and 5:

    let ModuleDecoratorDependency;
    try {
      ModuleDecoratorDependency = require("./dependencies/ModuleDecoratorDependency");
    } catch (e) {}
    
    // ... then replacing the above lines:
    
                } else if (ModuleDecoratorDependency) {
                  const dep = new ModuleDecoratorDependency(
                    ParserHelpers.getModulePath(parser.state.module.context, loaderRequest),
                    parser.state.module
                  );
                  dep.loc = expr.loc;
                  parser.state.module.addDependency(dep);
                }
              } else {
                // For CommonJS/Auto
                const req = `require(${JSON.stringify(loaderRequest)})`;
                ParserHelpers.toConstantDependency(parser, id)(expr.arguments[0]);
                ParserHelpers.addParsedVariableToModule(parser, id, req);
              }
  3. tsavo-vdb-knott commented on Sep 28, 2020

    @tsavo-vdb-knott

    This is also an issue for me. I attempted to add your above code however the error persists.

  4. phyllisstein commented on Sep 30, 2020

    @phyllisstein

    I wound up with a fresh error after making that change:

    ERROR in ./src/development/client.js
    Module parse failed: ParserHelpers.getModulePath is not a function
    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.
    TypeError: ParserHelpers.getModulePath is not a function
        at /Users/daniel/Code/NY/choreographer/node_modules/worker-plugin/src/index.js:123:29
        at Hook.eval (eval at create (/Users/daniel/Code/NY/choreographer/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
        at Hook.CALL_DELEGATE [as _call] (/Users/daniel/Code/NY/choreographer/node_modules/webpack/node_modules/tapable/lib/Hook.js:14:14)
        at JavascriptParser.callHooksForInfoWithFallback (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2871:24)
        at JavascriptParser.callHooksForExpressionWithFallback (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2782:16)
        at JavascriptParser.callHooksForExpression (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2750:15)
        at JavascriptParser.walkNewExpression (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2457:23)
        at JavascriptParser.walkExpression (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2185:10)
        at JavascriptParser.walkVariableDeclaration (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:2007:33)
        at JavascriptParser.walkStatement (/Users/daniel/Code/NY/choreographer/node_modules/webpack/lib/javascript/JavascriptParser.js:1528:10)
    

    Did a little digging in the Webpack sources; couldn't find anything germane.

  5. developit commented on Oct 1, 2020

    @developit
    Contributor

    FWIW Webpack 5 seems to have landed its own worker-plugin, which I guess means this plugin shouldn't be used with it.

  6. balloob commented on Oct 1, 2020

    @balloob
    Author

    For people exploring the Webpack 5 syntax:

    const worker = new Worker(new URL("./my_worker.js", import.meta.url));

    No extra plugin loading is required.

  7. phyllisstein commented on Oct 2, 2020

    @phyllisstein

    Oh wow, thanks! Totally missed that.

  8. yamafaktory commented on Oct 11, 2020

    @yamafaktory

    I was playing around with Webpack 5 + esbuild and now I think I'm clearly missing this plugin. The issue is that Webpack is now relying on import.meta.url which is not always available depending on your loader and on the selected target, see webpack/webpack#11439 (comment).

  9. vanduc1102 commented on Dec 24, 2021

    @vanduc1102

    Same for typescript

    const worker = new Worker(new URL('./workers/foo.worker.ts', import.meta.url));

    https://github.com/azangru/web-worker-ts-webpack-test/blob/master/src/index.ts#L11

  10. axetroy commented on Jun 14, 2024

    @axetroy

    Unfortunately, Webpack5's Web Worker solution relies on import.meta.url, which is not compatible friendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions