diff --git a/packages/uni-cli-i18n/locales/en.json b/packages/uni-cli-i18n/locales/en.json index 2dfce1c3048a96c1760ad25c87ac1a07244baaf5..be37499fc1bac44ca50ef4539a0257de2a834d93 100644 --- a/packages/uni-cli-i18n/locales/en.json +++ b/packages/uni-cli-i18n/locales/en.json @@ -7,7 +7,7 @@ "platform": "platform", "plugin": "plugin", "performingHotReload": "Performing hot reload...", - "cliShared.parsingFailed": "Parsing failed", + "cliShared.parseJsonFailed": "Parsing failed", "cliShared.doesNotExist": "does not exist", "cliShared.pagesJsonError": "pages.json page configuration error, has been ignored, see {{0}}", "cliShared.requireReturnJsonObject": "require return a json object", diff --git a/packages/uni-cli-i18n/locales/zh_CN.json b/packages/uni-cli-i18n/locales/zh_CN.json index 8f5dda83887d053a62c4d8c9b97655a4e5901dcc..c48eb8b62b563ef14075e66adc40656af5050389 100644 --- a/packages/uni-cli-i18n/locales/zh_CN.json +++ b/packages/uni-cli-i18n/locales/zh_CN.json @@ -7,7 +7,7 @@ "platform": "平台", "plugin": "插件", "performingHotReload": "正在差量编译...", - "cliShared.parsingFailed": "解析失败", + "cliShared.parseJsonFailed": "解析失败,不符合 json 规范", "cliShared.doesNotExist": "不存在", "cliShared.pagesJsonError": "pages.json 页面配置错误,已被忽略,查看文档: {{0}}", "cliShared.requireReturnJsonObject": "必须返回一个 json 对象", diff --git a/packages/uni-cli-shared/lib/json.js b/packages/uni-cli-shared/lib/json.js index 810173e88f4a1d0805b4bc0585f8fbc084d8c5cc..09afa37fef462af5bfd9faff11357444002fc66d 100644 --- a/packages/uni-cli-shared/lib/json.js +++ b/packages/uni-cli-shared/lib/json.js @@ -14,12 +14,7 @@ function parseJson (content, preprocess = false) { type: jsPreprocessOptions.type }) } - - try { - content = JSON.parse(stripJsonComments(content)) - } catch (e) { - throw new Error('uni-app-compiler: ' + e.message) - } + content = JSON.parse(stripJsonComments(content)) } content = JSON.stringify(content) @@ -37,11 +32,11 @@ function getJson (jsonFileName, preprocess = false) { try { return parseJson(fs.readFileSync(jsonFilePath, 'utf8'), preprocess) } catch (e) { - console.error(jsonFileName + uniI18n.__('cliShared.parsingFailed')) + throw new Error(jsonFileName + uniI18n.__('cliShared.parseJsonFailed') + '\n' + e.message) } } module.exports = { getJson, parseJson -} +}