webpack-contrib / webpack-serve

Repository has moved:
https://github.com/shellscape/webpack-serve
MIT License
1.09k stars 83 forks source link

TypeError: Cannot read property 'watchRun' of undefined #84

Closed wzup closed 6 years ago

wzup commented 6 years ago

This issue is for a:

Code

CLI Command
$ node serve.config.js
webpack.config.js

https://gist.github.com/wzup/54d2a81c10ab8d22a66e53f22fd2e07a

Config serve.config.js:

'use strict';

const serve = require('webpack-serve');
const wpConfig = require('./webpack.config.js');

let serverConfig = {
    hot: true,           // Instruct the client not to apply Hot Module Replacement patches
}

serve({
    options: serverConfig,
    config: wpConfig,
});

Expected Behavior

Runnig webpack-serve server

Actual Behavior

Error thrown

An error was thrown while starting webpack-serve.
   Error: An error was thrown while initializing Webpack
  TypeError: Cannot read property 'watchRun' of undefined
    at getOptions.then (/home/user/app//node_modules/webpack-serve/index.js:35:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:686:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Error: An error was thrown while initializing Webpack
  TypeError: Cannot read property 'watchRun' of undefined
    at getOptions.then (/home/user/app//node_modules/webpack-serve/index.js:35:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:686:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

How Do We Reproduce?

Same way

Config serve.config.js

'use strict';

const serve = require('webpack-serve');
const wpConfig = require('./webpack.config.js');

let serverConfig = {
    hot: true,   // Instruct the client not to apply Hot Module Replacement patches
}

serve({
    options: serverConfig,
    config: wpConfig,
});
shellscape commented 6 years ago

You chose to ignore the warning in the issue template and removed a bunch of useful sections! Sad panda 🐼 If you edit your issue to include the sections you removed, we'll reopen this.

watchRun doesn't appear anywhere in this repository: https://github.com/webpack-contrib/webpack-serve/search?utf8=%E2%9C%93&q=watchRun&type=

wzup commented 6 years ago

@shellscape What benefit do I get if include all the sections? Will you provide a solution for the issue?

shellscape commented 6 years ago

Well, if you would have followed the issue template (like the template instructs you to) then you would have provided your webpack.config.js and I would have been able to identify erroneous properties. But you didn't, so I can't. If you can't take the time to follow simple instructions so we can help you efficiently, we won't take the time to try. Simple as that.

If you examine the error message you pasted and consider that the property mentioned in the TypeError doesn't exist in this repository, you'll arrive at your answer. This is basic debugging.

wzup commented 6 years ago

@shellscape Fair enough. I've updated my issue and added up all the missing data

shellscape commented 6 years ago

Yes, but it appears you didn't fully grok the second half of my comment:

If you examine the error message you pasted and consider that the property mentioned in the TypeError doesn't exist in this repository, you'll arrive at your answer.

The problem exists within your webpack.config.js. Specifically because you're using webpack-spritesmith which is the culprit for throwing the error. See: https://github.com/mixtur/webpack-spritesmith/blob/8e146881c439d4df142bbcd7b7f8f9e8cc8aba2c/lib/Plugin.js#L38

This is pretty basic debugging - look at what doesn't fit and investigate. How did I arrive at this?

  1. Examined webpack.config.js. Nothing out of the ordinary. No bad properties in the config.
  2. Looked for plugins in the config.
  3. Found plugin, went to it's repo.
  4. Searched for watchRun in the repo.
  5. Found watchRun

Contact that repository about the bug. webpack-serve is not responsible for that TypeError.

wzup commented 6 years ago

@shellscape Thanks for the tip on how to search for errors 👍

BTW, it was not webpack-spritesmith issue. It was an issue of webpack itself. Because of its outdated version. I've updated webpack to ^4.4.1 and the initial error has gone away. But many more errors emerged because of all the other modules were outdated too.

So, the solution to initial issue is to update webpack.