[内容]
uniapp的pages.json条件编译时jshint校验不通过
重现步骤
[步骤]
在pages.json中配置
"globalStyle": {
//#ifdef MP
"navigationBarTextStyle": "white",
"navigationBarTitleText": "XXX",
"navigationBarBackgroundColor": "#25b864",
"backgroundColor": "#25b864",
//#endif
//#ifdef APP-PLUS
"navigationBarTextStyle": "white",
"navigationBarTitleText": "XXXX",
"navigationBarBackgroundColor": "#25b864",
"backgroundColor": "#25b864"
//#endif
}
进行编译
[结果]
jshint校验不通过,因为在同一个对象中有同Key的属性
[期望]
可以编译通过,或者可以关闭jshint,或者可以修改jshint规则
[如果语言难以表述清晰,可以拍一个视频或截图,有图有真相]
IDE运行环境说明
[HBuilder 或 HBuilderX] HBuilderX
[IDE版本号] 1.5.4
[mac版本号] macos 10.14.3
联系方式
[mail] jack_wangyubo@163.com
7 个回复
Neil_HL
可以配置app-plus节点,在里面设置app的文字内容和颜色,在json里面相同的key肯定报错
9***@qq.com
如果要条件编译的不是app-plus的节点,例如配置navigationBarTitleText,这样就会报错,无法编译
DCloud_heavensoft
jshint这些校验插件,不认识json里的条件编译格式,会乱报警,不用理会,不影响编译
2***@qq.com
同问,HBuilderX里编译也校验不通过的
2020-03-15 14:21
DCloud_HB_WKP
回复 2***@qq.com: 请给一下详细的错误信息,最好单独开一个帖子说明一下。
2020-03-17 19:45
2***@qq.com
回复 DCloud_HB_WKP:
(1). 使用的HBuilderX 版本号:v2.6.5;
(2). 项目创建方式:HBuilderX新建的uni-app;
(3). pages.json配置代码如下:
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "xxx"
}
}
],
// #ifndef H5
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "xxx",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
// #endif
}
(4). H5编译通过,一切正常;
(5). 小程序编译报错信息如下:
10:52:27.429 项目 'apphndlcloud' 开始编译...
10:52:30.957 pages.json 解析失败
10:52:30.961 D:\Tools\IDE\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-cli-shared\lib\pages.js:73
10:52:30.973 if (pagesJson.pages && pagesJson.pages.length) { // 如果首页是 nvue
10:52:30.977 ^
10:52:30.993 TypeError: Cannot read property 'pages' of undefined
10:52:30.993 at processPagesJson (D:\Tools\IDE\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-cli-shared\lib\pages.js:73:17)
10:52:31.013 at getPagesJson (D:\Tools\IDE\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-cli-shared\lib\pages.js:37:10)
10:52:31.029 at Object.<anonymous> (D:\Tools\IDE\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\lib\env.js:90:22)
10:52:31.049 at Module._compile (module.js:652:30)
10:52:31.066 at Object.Module._extensions..js (module.js:663:10)
10:52:31.086 at Module.load (module.js:565:32)
10:52:31.086 at tryModuleLoad (module.js:505:12)
10:52:31.106 at Function.Module._load (module.js:497:3)
10:52:31.106 at Module.require (module.js:596:17)
10:52:31.122 at require (internal/module.js:11:18)
2020-03-21 11:09
9***@qq.com
感谢回答。使用的是HBuilderX,版本号:1.9.4.20190426,代码如下:
"path": "pages/component/view/view",
"style": {
// #ifdef H5
"navigationBarTitleText": "view",
// #endif
// #ifndef H5
"navigationBarTitleText": "demo"
// #endif
}
编译报错:[JSHINT] 16:48:44.978 E:/path/to/pages.json: line 73, col 17, Duplicate key 'navigationBarTitleText'.
2***@qq.com
(1). 使用的HBuilderX 版本号:v2.6.5;
(2). 项目创建方式:HBuilderX新建的uni-app;
(3). pages.json配置代码如下:
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "xxx"
}
}
],
// #ifndef H5
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "xxx",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
// #endif
}
(4). H5编译通过,一切正常;
(5). 小程序编译报错信息如下:
10:52:27.429 项目 'apphndlcloud' 开始编译...
10:52:30.957 pages.json 解析失败
10:52:30.961 D:\Tools\IDE\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-cli-shared\lib\pages.js:73
10:52:30.973 if (pagesJson.pages
吴克
遇到同样问题
吴克
13:31:07.114 项目 'xxx' 开始编译...
[JSHINT] 13:31:08.325 C:/Users/huget/Documents/HBuilderProjects/gamer/pages.json: line 233, col 13, Expected ']' and instead saw '{'.
[JSHINT] 13:31:08.332 C:/Users/huget/Documents/HBuilderProjects/gamer/pages.json: line 234, col 17, Expected '}' and instead saw 'pagePath'.
[JSHINT] 13:31:08.360 C:/Users/huget/Documents/HBuilderProjects/gamer/pages.json: line 234, col 27, Expected '}' and instead saw ':'.
[JSHINT] 13:31:08.367 4 errors
13:31:08.389 项目 'xxx' 编译失败。
说明JSHINT会导致项目编译失败