Skip to content

Commit

Permalink
fix: more helpful error message when subapp init fail on server
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Oct 15, 2020
1 parent 6171208 commit ffe4560
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions packages/subapp-web/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,27 @@ ${ignoreMsg}`
* @returns {Promise.<Object>} an object containing an array of file names
*/
loadAssetsFromStats(statsPath) {
let stats;
const statsFile = Path.resolve(statsPath);

let stats;
try {
stats = JSON.parse(Fs.readFileSync(Path.resolve(statsPath)).toString());
stats = JSON.parse(Fs.readFileSync(statsFile).toString());
} catch (err) {
throw new Error(
`Couldn't find stats.json at ${Path.resolve(
statsPath
)}. Please ensure environment is set up correctly. (Did you run 'clap dev'?)`
);
const msg = `
+------------
| ERROR: subapp-web couldn't load the file ${statsFile}.
|
| This likely means that there was an error with webpack compile process.
| Please check in the terminal if status message indicates webpack bundle
| has ERRORS, and then look for webpack dev server reporter URL and open
| it to view webpack compile results.
|
| Also, in dev mode you should be starting with the command 'clap dev'.
|
| Continuing or reloading will result in further strange errors.
+------------
`;
throw new Error(msg);
}

const assets = {};
Expand Down Expand Up @@ -354,7 +365,7 @@ ${ignoreMsg}`

if (data.action === "group-ssr-total" || data.action === "subapps-ssr") {
const events = groupEvents[group];
events.forEach((event) => reporter(event));
events.forEach(event => reporter(event));
delete groupEvents[group];
}
});
Expand Down

0 comments on commit ffe4560

Please sign in to comment.