Skip to content

require("") causes obscure error #2006

Closed

Description

@fresheneesz

I accidentally left a blank string in a require and got this confusing error:

Module build failed: Error: Final loader didn't return a Buffer or String
    at DependenciesBlock.onModuleBuild (/home/vagrant/backend/node_modules/webpack-core/lib/NormalModuleMixin.js:299:42)
    at nextLoader (/home/vagrant/backend/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at DependenciesBlock.onLoadPitchDone (/home/vagrant/backend/node_modules/webpack-core/lib/NormalModuleMixin.js:262:4)
    at DependenciesBlock.loadPitch (/home/vagrant/backend/node_modules/webpack-core/lib/NormalModuleMixin.js:182:27)
    at DependenciesBlock.doBuild (/home/vagrant/backend/node_modules/webpack-core/lib/NormalModuleMixin.js:241:4)
    at DependenciesBlock.build (/home/vagrant/backend/node_modules/webpack/lib/NormalModule.js:84:14)
    at Compilation.buildModule (/home/vagrant/backend/node_modules/webpack/lib/Compilation.js:126:9)
    at /home/vagrant/backend/node_modules/webpack/lib/Compilation.js:309:10
    at /home/vagrant/backend/node_modules/webpack/lib/NormalModuleFactory.js:58:13
    at NormalModuleFactory.applyPluginsAsyncWaterfall (/home/vagrant/backend/node_modules/tapable/lib/Tapable.js:75:69)
 @ ./backend/git/frontend/~/view/Notifications.js 12:0-11

Its not too bad since it does reference the correct file, but it seems like something internal is going wrong here.

Activity

  1. IngwiePhoenix commented on Feb 6, 2016

    @IngwiePhoenix

    Simply put: Webpack is confused.

    The input is empty, the loader list did not get any match, and anything thus everything is empty. Webpack is simply going bananas :). There is no short-chircuit for an empty require call.

  2. fresheneesz commented on Feb 6, 2016

    @fresheneesz
    ContributorAuthor

    Maybe there should be? Why not have the same "module not found" error for an empty string? Why is it different from a normal unfound file?

  3. IngwiePhoenix commented on Feb 6, 2016

    @IngwiePhoenix

    Webpack actually doesnt search for the module first. When it finds a require statement, the string within is parsed into a Dependency - an internal class, so to say. First, Webpack looks up any kind of loader that could be used. The way it does that is by searching the list of loaders within module.loaders of your config, and I believe there are even internal loaders as well, mainly for .js I believe. Alternatively, there is a catch-all-and-return loader that simply does zero processing and passes the file to webpack's Parser.

    Once a loader is found, the actual request - which is the path to the resolved file - is passed to the loader. Noticed something? Our request is empty. So there is no file that we need to resolve. WebPack has it's own resolver, and I believe it has no method of handling empty files. In fact, this would make a great test case for unit tests :).

    So WebPack puts the empty request to the catch-all-and-return loader, which returns nothing. Why should it? There is nothing to do about it. Its empty. So this is why the error actually reads "Final loader didn't return a Buffer or String"...because it returned nothing, plain and simple.

    That is also why you don't get a "Module not found" error. Because if Webpack has a path, it can try to resolve it. When it doesnt find it, then that means that the module can't be found. But empty module requests are...appearently not being taken into account.

    I believe @sokra could do something here. I would've written the unit test but I am not sure how to best reproduce this - never wrote a unit test with webpack. So Ill let this one be up to him :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions