From 52aa0be49a17d6001b3dff8345e9b66945226558 Mon Sep 17 00:00:00 2001 From: Jevon Wright Date: Sat, 22 Jul 2017 17:34:10 +1200 Subject: [PATCH] Fail if NODE_ENV is not set when running webpack On a brand new install, if NODE_ENV is not already set, then running `bin/webpack` will fail with an obscure error message: path: resolve('public', settings.public_output_path), ^ TypeError: Cannot read property 'public_output_path' of undefined at Object. (.../config/webpack/configuration.js:26:35) Since someone will never be able to run webpack without NODE_ENV set, it makes sense to give the developer a message to help them debug. --- lib/install/config/webpack/configuration.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/install/config/webpack/configuration.js b/lib/install/config/webpack/configuration.js index 0d669ff0a..f130cc6ea 100644 --- a/lib/install/config/webpack/configuration.js +++ b/lib/install/config/webpack/configuration.js @@ -22,6 +22,10 @@ function formatPublicPath(host = '', path = '') { return `${formattedHost}/${formattedPath}/` } +if (typeof env.NODE_ENV == 'undefined') { + throw "Cannot start webpack: ENV[NODE_ENV] not set." +} + const output = { path: resolve('public', settings.public_output_path), publicPath: formatPublicPath(env.ASSET_HOST, settings.public_output_path)