You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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 :)
Activity
IngwiePhoenix commentedon Feb 6, 2016
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.
fresheneesz commentedon Feb 6, 2016
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?
IngwiePhoenix commentedon Feb 6, 2016
Webpack actually doesnt search for the module first. When it finds a
requirestatement, the string within is parsed into aDependency- 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 withinmodule.loadersof your config, and I believe there are even internal loaders as well, mainly for.jsI 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 :)