TypeError: Cannot read property ‘outputOptions’ of undefined

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Build fails.

$ webpack --env.app=pdf
(node:7276) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead
(node:7276) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
C:\Users\wojte\Projekty\react-pdf\node_modules\webpack\lib\webworker\WebWorkerMainTemplatePlugin.js:97
                        hash.update(`${this.outputOptions.publicPath}`);
                                            ^

TypeError: Cannot read property 'outputOptions' of undefined
    at C:\Users\wojte\Projekty\react-pdf\node_modules\webpack\lib\webworker\WebWorkerMainTemplatePlugin.js:97:24
    at SyncHook.eval [as call] (eval at create (C:\Users\wojte\Projekty\Project showcase\node_modules\tapable\lib\HookCodeFactory.js:17:12), <anonymous>:7:1)
    at SyncHook.lazyCompileHook [as _call] (C:\Users\wojte\Projekty\Project showcase\node_modules\tapable\lib\Hook.js:35:21)
    at MainTemplate.updateHash (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\MainTemplate.js:390:19)
    at Compilation.createHash (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compilation.js:1647:21)
    at hooks.optimizeTree.callAsync.err (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compilation.js:924:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\wojte\Projekty\Project showcase\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (C:\Users\wojte\Projekty\Project showcase\node_modules\tapable\lib\Hook.js:35:21)
    at Compilation.seal (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compilation.js:881:27)
    at hooks.make.callAsync.err (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compiler.js:464:17)
    at _err0 (eval at create (C:\Users\wojte\Projekty\Project showcase\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:11:1)
    at _addModuleChain (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compilation.js:749:12)
    at processModuleDependencies.err (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compilation.js:688:9)
    at process._tickCallback (internal/process/next_tick.js:150:11)
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: C:\\WINDOWS\\system32\\cmd.exe
Arguments: /d /s /c webpack --env.app=pdf

As you can see, I actually build several “apps” with one config, and app is an env variable. Interestingly, only one of these variables fail. The only difference I can see is that pdf app uses this file. This makes me wonder if that should be filed against worker-loader, but it is nowhere mentioned in this particular error stack.

The first two lines of call stack are the most interesting ones – as you can see, it actually seemed to jump from one webpack to another, and indeed react-pdf has webpack 3.x in its dependencies. Interestingly, this caused another error:

$ webpack --env.app=pdf
Hash: 9d98738b1866ccee2b7a
Version: webpack 4.1.1
Time: 28419ms
Built at: 2018-3-19 01:43:36
 8 assets
Entrypoint main = bundle.js
  [12] C:/Users/wojte/Projekty/react-pdf/dist/shared/utils.js 7.84 KiB {2} [built]
 [109] ./pdf/config.json 174 bytes {2} [built]
(truncated)
 [178] ./style.less 1.2 KiB {2} [built]
 [373] C:/Users/wojte/Projekty/react-pdf/dist/entry.webpack.js 1.2 KiB {2} [built]
 [384] ./pdf/index.jsx 4.97 KiB {2} [built]
    + 411 hidden modules

ERROR in C:/Users/wojte/Projekty/react-pdf/node_modules/worker-loader/dist/cjs.js!C:/Users/wojte/Projekty/react-pdf/node_modules/pdfjs-dist/build/pdf.worker.js
Module build failed: Error: Cannot find module 'webpack/lib/node/NodeTargetPlugin'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (C:\Users\wojte\Projekty\Project showcase\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\Users\wojte\Projekty\react-pdf\node_modules\worker-loader\dist\index.js:21:25)
    at Module._compile (C:\Users\wojte\Projekty\Project showcase\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (C:\Users\wojte\Projekty\Project showcase\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\Users\wojte\Projekty\react-pdf\node_modules\worker-loader\dist\cjs.js:3:14)
    at Module._compile (C:\Users\wojte\Projekty\Project showcase\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (C:\Users\wojte\Projekty\Project showcase\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at loadLoader (C:\Users\wojte\Projekty\Project showcase\node_modules\loader-runner\lib\loadLoader.js:13:17)
    at iteratePitchingLoaders (C:\Users\wojte\Projekty\Project showcase\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
    at runLoaders (C:\Users\wojte\Projekty\Project showcase\node_modules\loader-runner\lib\LoaderRunner.js:362:2)
    at NormalModule.doBuild (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\NormalModule.js:219:3)
    at NormalModule.build (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\NormalModule.js:337:15)
    at Compilation.buildModule (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compilation.js:346:10)
    at factory.create (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\Compilation.js:572:15)
    at factory (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\NormalModuleFactory.js:366:6)
    at hooks.afterResolve.callAsync (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\NormalModuleFactory.js:143:13)
    at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (C:\Users\wojte\Projekty\Project showcase\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:18:1)
    at resolver (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\NormalModuleFactory.js:126:29)
    at process.nextTick (C:\Users\wojte\Projekty\Project showcase\node_modules\webpack\lib\NormalModuleFactory.js:304:9)
    at process._tickCallback (internal/process/next_tick.js:150:11)
 @ C:/Users/wojte/Projekty/react-pdf/node_modules/pdfjs-dist/webpack.js 18:18-64
 @ C:/Users/wojte/Projekty/react-pdf/dist/entry.webpack.js
 @ ./pdf/index.jsx
Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
       [3] ../node_modules/html-webpack-plugin/lib/loader.js!./index.html 1.15 KiB {0} [built]
        + 3 hidden modules
error An unexpected error occurred: "Command failed.
Exit code: 2
Command: C:\\WINDOWS\\system32\\cmd.exe
Arguments: /d /s /c webpack --env.app=pdf

Now we have a problem in worker-loader instead. Double checked the version and it’s the newest 1.1.1 that should be supporting Webpack 4.x. What’s going on?

What is the expected behavior?

  • Webpack should not jump to another copies of itself if found somewhere else in the directory tree (perhaps the issue here is with using symlinks).
  • worker-loader should be working okay with Webpack 4.x

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Node.js: 9.x
Webpack:
affected: 4.1.1
not affected: 3.11.0
OS: Windows 10 Spring Creators Update

Author: Fantashit

6 thoughts on “TypeError: Cannot read property ‘outputOptions’ of undefined

  1. Easy reproduction: for me it started to happen when I added MiniCssExtractPlugin (and its loader) in combination with thread-loader.

  2. Also using MiniCssExtractPlugin with HappyPack, can relate (falling back to not using HappyPack for the time being)

  3. Easy reproduction: for me it started to happen when I added MiniCssExtractPlugin (and its loader) in combination with thread-loader.

    Exactly the same for me:
    use: [ "thread-loader", MiniCssExtractPlugin.loader, "css-loader", "postcss-loader" ]

Comments are closed.

TypeError: Cannot read property ‘outputOptions’ of undefined

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

It fails and I don’t know how to isolate and reproduce it since my project has 300+ files.
It only uses ts-loader and url-loader. I hope this stack trace helps.

Also, following the stack trace we can clearly see that the function being called is not being called with apply or call, ergo the this.outputOptions will be null

If the current behavior is a bug, please provide the steps to reproduce.

/Users/menduz/code/client/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js:97
                        hash.update(`${this.outputOptions.publicPath}`);
                                            ^

TypeError: Cannot read property 'outputOptions' of undefined
    at /Users/menduz/code/client/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js:97:24
    at SyncHook.eval [as call] (eval at create (/Users/menduz/code/script/node_modules/tapable/lib/HookCodeFactory.js:17:12), <anonymous>:7:1)
    at SyncHook.lazyCompileHook [as _call] (/Users/menduz/code/script/node_modules/tapable/lib/Hook.js:35:21)
    at MainTemplate.updateHash (/Users/menduz/code/script/node_modules/webpack/lib/MainTemplate.js:394:19)
    at Compilation.createHash (/Users/menduz/code/script/node_modules/webpack/lib/Compilation.js:1663:21)
    at hooks.optimizeTree.callAsync.err (/Users/menduz/code/script/node_modules/webpack/lib/Compilation.js:939:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/menduz/code/script/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/Users/menduz/code/script/node_modules/tapable/lib/Hook.js:35:21)
    at Compilation.seal (/Users/menduz/code/script/node_modules/webpack/lib/Compilation.js:896:27)
    at hooks.make.callAsync.err (/Users/menduz/code/script/node_modules/webpack/lib/Compiler.js:479:17)
    at _err0 (eval at create (/Users/menduz/code/script/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)
    at _addModuleChain (/Users/menduz/code/script/node_modules/webpack/lib/Compilation.js:764:12)
    at processModuleDependencies.err (/Users/menduz/code/script/node_modules/webpack/lib/Compilation.js:703:9)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Author: Fantashit

1 thought on “TypeError: Cannot read property ‘outputOptions’ of undefined

  1. Looks like you have mixed up multiple installations of webpack

    • /Users/menduz/code/client/node_modules/webpack
    • /Users/menduz/code/script/node_modules/webpack

Comments are closed.