uni-app 编译支付宝小程序报错

uni-app 编译支付宝小程序报错

操作步骤

当前这边项目运行便会这样

预期结果

正常也是页面内容

实际结果

仍然如上图

Image

bug描述

Failed to compile
error[Parse]: c:/project/guyancong/wx-ZuPing/unpackage/dist/dev/mp-alipay/uni_modules/uview-plus/components/u-search/u-search.js: Unexpected token, expected (
—> …sourcemap\mp-alipay\uni_modules\uview-plus\components\u-search\u-search.vue:189:16
187 | // 收起键盘
188 | uni.hideKeyboard();

189 | } catch (e) {}
| ^
190 | },
191 | // 点击右边自定义按钮的事件
192 | custom() {

help: try fix it by editing the source file
note: the code is built into file c:\project\guyancong\wx-ZuPing\unpackage\dist\dev\mp-alipay\uni_modules\uview-plus\components\u-search\u-search.js

error[Parse]: c:/project/guyancong/wx-ZuPing/unpackage/dist/dev/mp-alipay/common/vendor.js: Unexpected token
—> …sourcemap\mp-alipay\common\vue.runtime.esm.js:290:45
288 | for (const effect2 of dep.keys()) {
289 | let tracking;

290 | if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
| ^
291 | effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
292 | effect2._dirtyLevel = dirtyLevel;
293 | }

help: try fix it by editing the source file
note: the code is built into file c:\project\guyancong\wx-ZuPing\unpackage\dist\dev\mp-alipay\common\vendor.js

error[Parse]: c:/project/guyancong/wx-ZuPing/unpackage/dist/dev/mp-alipay/uni_modules/uview-plus/libs/function/test.js: Unexpected token, expected (
—> …sourcemap\mp-alipay\uni_modules\uview-plus\libs\function\test.js:216:20
214 | }
215 | return false

216 | } catch (e) {
| ^
217 | return false
218 | }
219 | }

help: try fix it by editing the source file
note: the code is built into file c:\project\guyancong\wx-ZuPing\unpackage\dist\dev\mp-alipay\uni_modules\uview-plus\libs\function\test.js

error[Parse]: c:/project/guyancong/wx-ZuPing/unpackage/dist/dev/mp-alipay/uni_modules/uview-plus/libs/luch-request/adapters/index.js: Unexpected token, expected (
—> …sourcemap\mp-alipay\uni_modules\uview-plus\libs\luch-request\adapters\index.js:35:24
33 | }
34 | // eslint-disable-next-line no-empty

35 | } catch (e) {
| ^
36 | }
37 | settle(resolve, reject, response)
38 | }

help: try fix it by editing the source file
note: the code is built into file c:\project\guyancong\wx-ZuPing\unpackage\dist\dev\mp-alipay\uni_modules\uview-plus\libs\luch-request\adapters\index.js

error[Parse]: c:/project/guyancong/wx-ZuPing/unpackage/dist/dev/mp-alipay/uni_modules/uview-plus/libs/luch-request/utils/clone.js: Unexpected token, expected (
—> …sourcemap\mp-alipay\uni_modules\uview-plus\libs\luch-request\utils\clone.js:12:13
10 | try {
11 | nativeMap = Map;

12 | } catch(_) {
| ^
13 | // maybe a reference error because no Map. Give it a dummy value that no
14 | // value will ever be an instanceof.
15 | nativeMap = function() {};

help: try fix it by editing the source file
note: the code is built into file c:\project\guyancong\wx-ZuPing\unpackage\dist\dev\mp-alipay\uni_modules\uview-plus\libs\luch-request\utils\clone.js

开发环境信息

项目创建方式 PC开发环境操作系统 PC开发环境操作系统版本号 HBuilderX类型 HBuilderX版本号 第三方开发者工具版本号 基础库版本号
HBuilderX Windows 4.45 正式 4.45 Version 3.9.22 最新

更多关于uni-app 编译支付宝小程序报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

6 回复

一个月前是使用过的,可以正常使用,今天再打开就不可以了

更多关于uni-app 编译支付宝小程序报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html


给一个空白复现工程。你排查一下 u-search.js 是不是有语法错误

下方是全部代码,这边看一下报错是在catch这里,不明白为什么,因为之前是没问题的

<template> <view class="u-search" @tap="clickHandler" :style="[{ margin: margin, }, addStyle(customStyle)]" > <view class="u-search__content" :style="{ backgroundColor: bgColor, borderRadius: shape == 'round' ? '100px' : '4px', borderColor: borderColor, }" > <template v-if="$slots.label || label !== null"> <slot name="label"> <text class="u-search__content__label">{{ label }}</text> </slot> </template> <view class="u-search__content__icon"> <u-icon @tap="clickIcon" :size="searchIconSize" :name="searchIcon" :color="searchIconColor ? searchIconColor : color" ></u-icon> </view> <input confirm-type="search" @blur="blur" :value="keyword" @confirm="search" @input="inputChange" :disabled="disabled" @focus="getFocus" :focus="focus" :maxlength="maxlength" :adjust-position="adjustPosition" :auto-blur="autoBlur" placeholder-class="u-search__content__input--placeholder" :placeholder="placeholder" :placeholder-style="`color: ${placeholderColor}`" class="u-search__content__input" type="text" :style="[{ textAlign: inputAlign, color: color, backgroundColor: bgColor, height: addUnit(height) }, inputStyle]" /> <view class="u-search__content__icon u-search__content__close" v-if="keyword && clearabled && focused" @click="clear" > <u-icon name="close" size="11" color="#ffffff" customStyle="line-height: 12px" ></u-icon> </view> </view> <text :style="[actionStyle]" class="u-search__action" :class="[(showActionBtn || show) && 'u-search__action--active']" @tap.stop.prevent="custom" >{{ actionText }}</text> </view> </template> <script> import { props } from './props'; import { mpMixin } from '../../libs/mixin/mpMixin'; import { mixin } from '../../libs/mixin/mixin'; import { addUnit, addStyle } from '../../libs/function/index'; /** * search 搜索框 * @description 搜索组件,集成了常见搜索框所需功能,用户可以一键引入,开箱即用。 * @tutorial https://ijry.github.io/uview-plus/components/search.html * @property {String} shape 搜索框形状,round-圆形,square-方形(默认 'round' ) * @property {String} bgColor 搜索框背景颜色(默认 '#f2f2f2' ) * @property {String} placeholder 占位文字内容(默认 '请输入关键字' ) * @property {Boolean} clearabled 是否启用清除控件(默认 true ) * @property {Boolean} focus 是否自动获得焦点(默认 false ) * @property {Boolean} showAction 是否显示右侧控件(默认 true ) * @property {Object} actionStyle 右侧控件的样式,对象形式 * @property {String} actionText 右侧控件文字(默认 '搜索' ) * @property {String} inputAlign 输入框内容水平对齐方式 (默认 'left' ) * @property {Object} inputStyle 自定义输入框样式,对象形式 * @property {Boolean} disabled 是否启用输入框(默认 false ) * @property {String} borderColor 边框颜色,配置了颜色,才会有边框 (默认 'transparent' ) * @property {String} searchIconColor 搜索图标的颜色,默认同输入框字体颜色 (默认 '#909399' ) * @property {Number | String} searchIconSize 搜索图标的字体,默认22 * @property {String} color 输入框字体颜色(默认 '#606266' ) * @property {String} placeholderColor placeholder的颜色(默认 '#909399' ) * @property {String} searchIcon 输入框左边的图标,可以为uView图标名称或图片路径 (默认 'search' ) * @property {String} margin 组件与其他上下左右元素之间的距离,带单位的字符串形式,如"30px" (默认 '0' ) * @property {Boolean} animation 是否开启动画,见上方说明(默认 false ) * @property {String} value 输入框初始值 * @property {String | Number} maxlength 输入框最大能输入的长度,-1为不限制长度 (默认 '-1' ) * @property {String | Number} height 输入框高度,单位px(默认 64 ) * @property {String | Number} label 搜索框左边显示内容 * @property {Boolean} adjustPosition 键盘弹起时,是否自动上推页面 * @property {Boolean} autoBlur 键盘收起时,是否自动失去焦点 * @property {Object} customStyle 定义需要用到的外部样式 * * @event {Function} change 输入框内容发生变化时触发 * @event {Function} search 用户确定搜索时触发,用户按回车键,或者手机键盘右下角的"搜索"键时触发 * @event {Function} custom 用户点击右侧控件时触发 * @event {Function} clear 用户点击清除按钮时触发 * @example <u-search placeholder="日照香炉生紫烟" v-model="keyword"></u-search> */ export default { name: "u-search", mixins: [mpMixin, mixin, props], data() { return { keyword: '', showClear: false, // 是否显示右边的清除图标 show: false, // 标记input当前状态是否处于聚焦中,如果是,才会显示右侧的清除控件 focused: this.focus // 绑定输入框的值 // inputValue: this.value }; }, watch: { keyword(nVal) { // 双向绑定值,让v-model绑定的值双向变化 // #ifdef VUE3 this.$emit("update:modelValue", nVal); // #endif // #ifdef VUE2 this.$emit('input', nVal); // #endif // 触发change事件,事件效果和v-model双向绑定的效果一样,让用户多一个选择 this.$emit('change', nVal); }, // #ifdef VUE3 modelValue: { immediate: true, handler(nVal) { this.keyword = nVal; } }, // #endif // #ifdef VUE2 value: { immediate: true, handler(nVal) { this.keyword = nVal; } }, // #endif }, computed: { showActionBtn() { return !this.animation && this.showAction } }, emits: ['clear', 'search', 'custom', 'focus', 'blur', 'click', 'clickIcon', 'update:modelValue', 'change'], methods: { addStyle, addUnit, // 目前HX2.6.9 v-model双向绑定无效,故监听input事件获取输入框内容的变化 inputChange(e) { this.keyword = e.detail.value; }, // 清空输入 // 也可以作为用户通过this.$refs形式调用清空输入框内容 clear() { this.keyword = ''; // 延后发出事件,避免在父组件监听clear事件时,value为更新前的值(不为空) this.$nextTick(() => { this.$emit('clear'); }) }, // 确定搜索 search(e) { this.$emit('search', e.detail.value); try { // 收起键盘 uni.hideKeyboard(); } catch (e) {} }, // 点击右边自定义按钮的事件 custom() { this.$emit('custom', this.keyword); try { // 收起键盘 uni.hideKeyboard(); } catch (e) {} }, // 获取焦点 getFocus() { this.focused = true; // 开启右侧搜索按钮展开的动画效果 if (this.animation && this.showAction) this.show = true; this.$emit('focus', this.keyword); }, // 失去焦点 blur() { // 最开始使用的是监听图标@touchstart事件,自从hx2.8.4后,此方法在微信小程序出错 // 这里改为监听点击事件,手点击清除图标时,同时也发生了@blur事件,导致图标消失而无法点击,这里做一个延时 setTimeout(() => { this.focused = false; }, 100) this.show = false; this.$emit('blur', this.keyword); }, // 点击搜索框,只有disabled=true时才发出事件,因为禁止了输入,意味着是想跳转真正的搜索页 clickHandler() { if (this.disabled) this.$emit('click'); }, // 点击左边图标 clickIcon(e) { this.$emit('clickIcon', this.keyword); try { // 收起键盘 uni.hideKeyboard(); } catch (e) {} } } } </script> <style lang="scss" scoped> [@import](/user/import) "../../libs/css/components.scss"; $u-search-content-padding: 0 10px !default; $u-search-label-color: $u-main-color !default; $u-search-label-font-size: 14px !default; $u-search-label-margin: 0 4px !default; $u-search-close-size: 20px !default; $u-search-close-radius: 100px !default; $u-search-close-bgColor: #C6C7CB !default; $u-search-close-transform: scale(0.82) !default; $u-search-input-font-size: 14px !default; $u-search-input-margin: 0 5px !default; $u-search-input-color: $u-main-color !default; $u-search-input-placeholder-color: $u-tips-color !default; $u-search-action-font-size: 14px !default; $u-search-action-color: $u-main-color !default; $u-search-action-width: 0 !default; $u-search-action-active-width: 40px !default; $u-search-action-margin-left: 5px !default; /* #ifdef H5 */ // iOS15在H5下,hx的某些版本,input type=search时,会多了一个搜索图标,进行移除 [type="search"]::-webkit-search-decoration { display: none; } /* #endif */ .u-search { @include flex(row); align-items: center; flex: 1; &__content { @include flex; align-items: center; padding: $u-search-content-padding; flex: 1; justify-content: space-between; border-width: 1px; border-color: transparent; border-style: solid; overflow: hidden; &__icon { @include flex; align-items: center; } &__label { color: $u-search-label-color; font-size: $u-search-label-font-size; margin: $u-search-label-margin; } &__close { width: $u-search-close-size; height: $u-search-close-size; border-top-left-radius: $u-search-close-radius; border-top-right-radius: $u-search-close-radius; border-bottom-left-radius: $u-search-close-radius; border-bottom-right-radius: $u-search-close-radius; background-color: $u-search-close-bgColor; @include flex(row); align-items: center; justify-content: center; transform: $u-search-close-transform; } &__input { flex: 1; font-size: $u-search-input-font-size; line-height: 1; margin: $u-search-input-margin; color: $u-search-input-color; &--placeholder { color: $u-search-input-placeholder-color; } } } &__action { font-size: $u-search-action-font-size; color: $u-search-action-color; width: $u-search-action-width; overflow: hidden; transition-property: width; transition-duration: 0.3s; /* #ifndef APP-NVUE */ white-space: nowrap; /* #endif */ text-align: center; &--active { width: $u-search-action-active-width; margin-left: $u-search-action-margin-left; } } } </style>

给的工程不完整,我使用下面代码表现正常,你可以继续这个 demo 重现你的问题。
<template>
<view>
<view>input 输入 123 会 hideKeyboard</view>
<input v-model="val" />
</view>
</template>

<script> export default { data() { return { val: '' } }, watch: { val(newVal) { if (newVal === '123') { console.log('trigger 123'); try { // 收起键盘 uni.hideKeyboard(); } catch (e) {} } } } } </script>

表现是正常的,删减下你的代码,或者提供一个完整的工程,你只给一点代码我运行不起来

在处理uni-app编译支付宝小程序报错的问题时,首先需要确保开发环境和依赖项正确配置。以下是一些常见的错误排查步骤及相应的代码示例,帮助你定位和解决编译错误。

1. 检查uni-app和支付宝小程序SDK版本

确保你的uni-app和支付宝小程序开发者工具都是最新版本。在package.json中查看uni-app的版本:

"dependencies": {
    "@dcloudio/uni-app": "^x.y.z"
}

更新uni-app:

npm update @dcloudio/uni-app

2. 检查支付宝小程序配置

确保manifest.json中支付宝小程序的配置正确,例如appid:

{
  "mp-alipay": {
    "appid": "your-alipay-appid",
    "setting": {
      "urlCheck": false
    }
  }
}

3. 编译日志分析

查看uni-app编译输出和支付宝小程序开发者工具的编译日志,找出具体错误信息。例如,如果报错信息提示缺少某个模块或文件,检查是否遗漏了相关依赖或资源文件。

4. 代码兼容性调整

支付宝小程序对JavaScript、CSS和HTML的支持与微信小程序略有不同,可能需要调整代码以适应支付宝小程序的环境。例如,避免使用不被支付宝小程序支持的API或语法。

5. 示例代码检查

以下是一个简单的uni-app页面示例,确保代码符合支付宝小程序规范:

<template>
  <view>
    <text>{{message}}</text>
  </view>
</template>

<script>
export default {
  data() {
    return {
      message: 'Hello, Alipay Mini Program!'
    };
  }
}
</script>

<style>
view {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
text {
  font-size: 24px;
}
</style>

6. 清理缓存和重新安装依赖

有时候,清理项目缓存和重新安装依赖可以解决编译问题:

npm cache clean --force
rm -rf node_modules
npm install

7. 使用条件编译

针对支付宝小程序做特定调整时,可以使用条件编译:

<!-- #ifdef MP-ALIPAY -->
<view>Alipay Specific Code</view>
<!-- #endif -->

确保按照上述步骤逐一排查,通常可以解决大部分编译错误。如果问题依然存在,建议查看uni-app和支付宝小程序的官方文档或社区论坛,获取更多专业帮助。

回到顶部