Skip to content

Commit d7f4b66

Browse files
committed
fix: ignore Invalid JSON in staticwebapp.config.json
Closes #372
1 parent cb9d9bb commit d7f4b66

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/core/utils/user-config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs, { promises as fsPromises } from "fs";
22
import type http from "http";
33
import path from "path";
44
import { DEFAULT_CONFIG } from "../../config";
5+
import { logger } from "./logger";
56
import { isHttpUrl } from "./net";
67
const { readdir, readFile } = fsPromises;
78

@@ -44,7 +45,14 @@ export async function findSWAConfigFile(folder: string) {
4445
const filename = path.basename(file) as string;
4546

4647
if (filename === DEFAULT_CONFIG.swaConfigFilename || filename === DEFAULT_CONFIG.swaConfigFilenameLegacy) {
47-
const config = JSON.parse((await readFile(file)).toString("utf-8"));
48+
let config = {} as SWAConfigFile;
49+
try {
50+
config = JSON.parse((await readFile(file)).toString("utf-8"));
51+
} catch (err) {
52+
logger.warn(``);
53+
logger.warn(`Error reading ${filename} configuration:`);
54+
logger.warn(`${(err as any).message} in "${file}"`);
55+
}
4856

4957
// make sure we are using the right SWA config file.
5058
// Note: some JS frameworks (eg. Nuxt, Scully) use routes.json as part of their config. We need to ignore those

0 commit comments

Comments
 (0)