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

使用Tauri的revoke API时出现TypeError: window.__TAURI_IPC__ is not a function错误

解决TypeError: window.TAURI_IPC is not a function问题

可能的原因及修复步骤

  • 确保在Tauri环境中运行代码
    这个错误核心原因是代码在普通浏览器环境执行,而非Tauri打包后的应用或开发模式窗口。直接在浏览器打开前端页面会缺少Tauri注入的IPC对象,必须用npm run tauri dev启动应用,或者打包后运行。

  • 检查@tauri-apps/api版本与Tauri核心版本匹配
    版本不兼容会导致IPC机制异常。执行以下命令查看并同步版本:

    # 查看当前安装的版本
    npm list @tauri-apps/api @tauri-apps/cli
    # 升级到匹配的最新稳定版
    npm install @tauri-apps/api@latest @tauri-apps/cli@latest
    
  • 验证tauri.conf.json的配置项
    确保tauri > allowlist > all设为true(开发阶段),或者至少开启了tauri > allowlist > tauri > revoke权限:

    {
      "tauri": {
        "allowlist": {
          "all": true,
          // 或者精准配置
          "tauri": {
            "revoke": true
          }
        }
      }
    }
    

    修改后重启Tauri开发服务生效。

  • 确认代码中正确导入并使用revoke方法
    确保导入路径正确,且在合适的时机调用(比如DOM加载完成后):

    import { revoke } from '@tauri-apps/api/tauri';
    
    // 确保在Tauri环境初始化后调用
    document.addEventListener('DOMContentLoaded', async () => {
      try {
        await revoke('your-permission-name');
      } catch (err) {
        console.error('Revoke failed:', err);
      }
    });
    
  • 清理缓存后重新构建
    清理前端缓存和Tauri构建缓存:

    # 清理前端缓存(比如Vue/React的缓存)
    rm -rf node_modules/.cache # 或对应框架的缓存目录
    # 清理Tauri构建缓存
    npm run tauri clean
    # 重新启动开发服务
    npm run tauri dev
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 18:37:05