webpack: 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

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 14
  • Comments: 27 (11 by maintainers)

Most upvoted comments

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

I also have this issues when using MiniCssExtractPlugin with HappyPack

loader: [MiniCssExtractPlugin.loader,
            'happypack/loader?id=style'
          ]

尝试使用这种方式解决了

@niieani Try put MiniCssExtractPlugin.loader before thread-loader, it works for me.

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" ]

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