使用wxcomponents后导致app平台编译失败
如图,红框中是报错。
原来编译运行在手机app是没有问题的,就是因为加入了wxcomponents文件夹,引入了微信小程序原生的组件,导致app编译不能通过

- 发布:2021-03-12 11:31
- 更新:2021-07-04 20:56
- 阅读:1342
wxml文件导致app编译失败


4***@qq.com - 157151
app平台编译的时候,会先将wxcomponents这个目录下面的小程序组件通过 @dcloudio/uni-migration 组件整合成vue文件,
如果wxml文件里面有esprima不能识别的语法,比如扩展操作符:...,就会出现问题,
具体的可以直接修改:/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/@dcloudio/uni-migration/lib/mp-weixin/transform/template-transformer/transform/traverse.js,const ast = recast.parse(const object = ${object}
) 这里try catch一下具体的错误
function transformTemplate(node, state) {
const attribs = node.attribs
if (attribs.name) {
const name = attribs.name
// 用于处理一个 wxml 文件内包含多个 template
attribs['v-if'] = `wxTemplateName === '${name}'`
delete attribs.name
state.templates.push(name)
} else if (attribs.is) {
const name = attribs.is
delete attribs.is
node.name = name
attribs['wx-template-name'] = name
const data = attribs.data
if (data && data.indexOf('{{') !== -1) {
const object = `{${parseMustache(data)}}`
attribs['v-bind'] = object
let ast;
try{
ast = recast.parse(`const object = ${object}`)
}catch(e){
console.log(e)
}
const props = state.props[name] || ['wxTemplateName']
ast.program.body[0].declarations[0].init.properties.forEach(property => props.push(property.key.name))
state.props[name] = [...new Set(props)]
delete attribs.data
}
}
}
解决方案:
1、使用 HBuilder X 2.7.14 版本试试
2、https://github.com/dcloudio/uni-app/blob/v2.0.0-27920200529001/packages/uni-migration/lib/mp-weixin/transform/template-transformer/transform/traverse.js 用这里的文件覆盖一下 /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/@dcloudio/uni-migration/lib/mp-weixin/transform/template-transformer/transform/traverse.js