Webpack bundled express app fails to lookup view Webpack bundled express app fails to lookup view express express

Webpack bundled express app fails to lookup view


I believe the answer lies in how webpack handles the special __dirname global variable. Webpack's default behavior is to replace __dirname with the "mock" value /. This can be seen in the error you get from express where it's looking for a file at the root of /views, not ./views.

The solution is to add the following section to your webpack configuration:

node: {  __dirname: true}

Here's the docs which explain this behavior:https://webpack.github.io/docs/configuration.html#node