You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在ReactJS应用中使用Azure AI Immersive Reader遇BadArgument错误求助

解决Azure AI Immersive Reader在React中出现"Content must not be null"的问题
  • 检查传入的Content结构有效性
    调用ImmersiveReader.launchAsync时,必须确保content参数的chunks数组包含至少一个带有非空text字段的对象。空数组或text为空字符串都会触发该错误。正确的结构示例:

    const content = {
      chunks: [
        {
          text: '待处理的目标文本',
          lang: 'zh'
        }
      ]
    };
    
  • 确保内容变量已正确初始化
    如果内容来自组件状态或props,在调用启动函数前要先判断内容是否存在,避免传入初始的null或undefined。例如:

    const [targetText, setTargetText] = useState('');
    
    const launchReader = async () => {
      if (!targetText.trim()) return; // 过滤空文本
      // 此处添加获取token和subdomain的逻辑
      await ImmersiveReader.launchAsync(token, subdomain, {
        chunks: [{ text: targetText, lang: 'zh' }]
      });
    };
    
  • 排查参数传递错误
    确认调用SDK时没有误将content参数传为null或undefined,检查变量命名、解构赋值是否正确,避免类似launchAsync(token, subdomain, null)这类错误写法。

  • 等待内容来源加载完成
    如果内容来自异步请求(如API调用),要确保请求成功返回有效数据后再调用启动函数,避免在数据未加载完成时传入未初始化的内容。

内容的提问来源于stack exchange,提问作者AddyProg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 19:33:14