pastelsky / bundlephobia

🏋️ Find out the cost of adding a new frontend dependency to your project
https://bundlephobia.com
MIT License
9.01k stars 223 forks source link

webpack-dev-server fails on client-side require #55

Open shellscape opened 6 years ago

shellscape commented 6 years ago

Type

Bug

Package name

webpack-dev-server

Entire error (stringified) I see in my browser console

I took it a bit further, since the API is throwing a 504. https://bundlephobia.com/api/size?package=webpack-dev-server&record=true returns the following raw output:

{
  "error":{
    "code":"MissingDependencyError",
    "message":"This package (or this version) uses `<code>webpack/hot</code>`, but does not specify them<br /> either as a dependency or a peer dependency",
    "details":{
      "name":"MissingDependencyError",
      "originalError":[
        "ModuleNotFoundError: Module not found: Error: Can't resolve 'webpack/hot' in '/tmp/tmp-build/node_modules/webpack-dev-server/client'",
        "Error: minifying bundle.js\nProcessTerminatedError: cancel after 2 retries!"
      ],
      "extra":{
        "missingModules":[
          "webpack/hot"
        ]
      }
    }
  }
}

While some of the code does indeed "require" webpack/hot, it's only in files bundled and served to the client. So it may be that bundlephobia is being overly aggressive in this case.

pastelsky commented 6 years ago

So here is how bundlephobia works. We emulate creation of a new project by the end user, and to the project's entry point, we import the requested package as a import pack from <requested-package> Then, to make sure that tree shaking doesn't come into play, we "use" the imported package.

Next the project is built out using webpack, with the generated entry point, just like a user would. Now while webpack resolves packages using its resolution mechanism, it can encounter packages that it cannot find. Hence this error.

I've been trying to write a webpack resolve plugin that ignores such "missing" dependencies and moves the build forward with appropriate warning anyway, though abandoned it midway due to lack of documentation around it. Would love to accept a PR arround this.

shellscape commented 6 years ago

@pastelsky looks like your comment was cut off.

pastelsky commented 6 years ago

Yeah, hard to get it right the first time when you're typing on mobile in a metro train, using Github's dektop UI.