Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小程序转成taro,Error: slot 的值必须是一个字符串 #1835

Closed
xrr0520 opened this issue Jan 7, 2019 · 10 comments
Closed

小程序转成taro,Error: slot 的值必须是一个字符串 #1835

xrr0520 opened this issue Jan 7, 2019 · 10 comments
Assignees

Comments

@xrr0520
Copy link

xrr0520 commented Jan 7, 2019

问题描述
小程序转成taro,Error: slot 的值必须是一个字符串

复现步骤
1.自定义组件,用到了slot

// 这里可以贴代码
<view class="{{['button', size ? 'button-' + size : '', type ? 'button-' + type : '', block ? 'button-block' : '', plain ? 'button-' + type + '-plain' : '', pill ? 'border-pill' : '', disable ? 'button-disable' : '']}}"
  hover-class="button-hover" style="{{otherStyle}}">
  <icon wx:if="{{loading}}" type="loading-circle" size="{{size}}" />
  <slot></slot>
</view>

报错信息

错误 组件转换 common/components/button/index.js
Error: slot 的值必须是一个字符串

1 | 
at Object.codeFrameError (/Users/rongrongxiong/.config/yarn/global/node_modules/@tarojs/taroize/lib/src/utils.js:84:12)
at enter (/Users/rongrongxiong/.config/yarn/global/node_modules/@tarojs/taroize/lib/src/wxml.js:117:39)
at NodePath._call (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/path/context.js:105:12)
at TraversalContext.visitQueue (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitMultiple (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/context.js:103:17)
at TraversalContext.visit (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/context.js:190:19)
at Function.traverse.node (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/index.js:114:17)
at NodePath.visit (/Users/rongrongxiong/.config/yarn/global/node_modules/babel-traverse/lib/path/context.js:115:19)

系统信息
Taro CLI 1.2.4 environment info:
System:
OS: macOS High Sierra 10.13.4
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.11.1 - /usr/local/bin/node
Yarn: 1.9.2 - /usr/local/bin/yarn
npm: 6.4.0 - /usr/local/bin/npm
npmPackages:
@tarojs/components: 1.2.4 => 1.2.4
@tarojs/plugin-babel: 1.2.4 => 1.2.4
@tarojs/plugin-csso: 1.2.4 => 1.2.4
@tarojs/plugin-sass: 1.2.4 => 1.2.4
@tarojs/plugin-uglifyjs: 1.2.4 => 1.2.4
@tarojs/router: 1.2.4 => 1.2.4
@tarojs/taro: 1.2.4 => 1.2.4
@tarojs/taro-alipay: 1.2.4 => 1.2.4
@tarojs/taro-h5: 1.2.4 => 1.2.4
@tarojs/taro-swan: 1.2.4 => 1.2.4
@tarojs/taro-weapp: 1.2.4 => 1.2.4
@tarojs/webpack-runner: 1.2.4 => 1.2.4
eslint-config-taro: 1.2.4 => 1.2.4
eslint-plugin-taro: 1.2.4 => 1.2.4

@taro-bot
Copy link

taro-bot bot commented Jan 7, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@xrr0520 xrr0520 changed the title 将原生小程序转成taro代码后,编译报错,Error: slot 的值必须是一个字符串 小程序转成taro,Error: slot 的值必须是一个字符串 Jan 7, 2019
@yuche yuche added the taroize label Jan 7, 2019
@yuche yuche self-assigned this Jan 7, 2019
@yuche
Copy link
Contributor

yuche commented Jan 7, 2019

单单这段代码无法复现,能正确编译出来:

<view class="{{['button', size ? 'button-' + size : '', type ? 'button-' + type : '', block ? 'button-block' : '', plain ? 'button-' + type + '-plain' : '', pill ? 'border-pill' : '', disable ? 'button-disable' : '']}}"
  hover-class="button-hover" style="{{otherStyle}}">
  <icon wx:if="{{loading}}" type="loading-circle" size="{{size}}" />
  <slot></slot>
</view>

@xrr0520
Copy link
Author

xrr0520 commented Jan 7, 2019

这是一个 component 其他代码我一起贴下

、、、js
Component({ properties: { size: String, type: String, otherStyle: String, plain: { type: Boolean, value: false, }, block: { type: Boolean, value: false, }, pill: { type: Boolean, value: false, }, disable: { type: Boolean, value: false, }, loading: { type: Boolean, value: false, }, }, })

、、、json
{ "component": true }

、、、wxml
<view class="{{['button', size ? 'button-' + size : '', type ? 'button-' + type : '', block ? 'button-block' : '', plain ? 'button-' + type + '-plain' : '', pill ? 'border-pill' : '', disable ? 'button-disable' : '']}}" hover-class="button-hover" style="{{otherStyle}}"> <icon wx:if="{{loading}}" type="loading-circle" size="{{size}}" /> <slot></slot> </view>

、、、bug截图
image

@xrr0520
Copy link
Author

xrr0520 commented Jan 7, 2019

image
hello 我找到你们相关转译的代码模块 方便教我怎么针对这部分代码 拿实际例子进行调试吗

@yuche
Copy link
Contributor

yuche commented Jan 7, 2019

你找到这个包的 index.js,他接受一个对象,

{
script: '你的 js 字符串',
wxml: '你的 wxml 字符串'
}

然后就是常规的 node.js 调试

@xrr0520
Copy link
Author

xrr0520 commented Jan 9, 2019

_1990f435-8926-4d4f-a769-2eb11aa3b959
attrs = [] =>nameAttr = undefined 即slot中省略name 会报错

@xrr0520
Copy link
Author

xrr0520 commented Jan 9, 2019

想问 187行 为啥要加上 else 讲道理不要也没有关系吧

@yuche
Copy link
Contributor

yuche commented Jan 9, 2019

的确是这样,我本地的包没有编译最新的代码

@yuche yuche closed this as completed in 81d615d Jan 9, 2019
@xrr0520
Copy link
Author

xrr0520 commented Jan 9, 2019

你们下一次发版 计划在什么时候

@yuche
Copy link
Contributor

yuche commented Jan 9, 2019

今天或明天

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants