question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack 5: ParserHelpers.addParsedVariableToModule is not a function

See original GitHub issue

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

Initially reported at https://github.com/GoogleChromeLabs/worker-plugin/pull/84#issuecomment-657003936 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)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

21reactions
balloobcommented, Oct 1, 2020

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.

1reaction
vanduc1102commented, Dec 24, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack library function is not a function - Stack Overflow
As the title says, i'm getting an error in the browser Uncaught TypeError: MYLIB.init is not a function . webpack.config.js:.
Read more >
worker-plugin - npm
Webpack plugin to bundle Workers automagically.. Latest version: 5.0.1, ... Compatibility Note: Webpack 5 now includes worker bundling.
Read more >
Plugins - webpack
A webpack plugin is a JavaScript object that has an apply method. This apply method is called by the webpack compiler, giving access...
Read more >
webpack @ 4.0.0-alpha.1 .. 4.0.0-alpha.2 - Package Diff
- parser.plugin("expression " + name,. - ParserHelpers.expressionIsUnsupported(name + " is not supported by webpack.") + parser.hooks.evaluateTypeof.for( ...
Read more >
Calcite Components with Webpack 5 - Esri Community
I am trying to incorporate Calcite Components into a Webpack 5 app. ... [webpack-cli] TypeError: compiler.plugin is not a function at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found