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

无法为Tauri项目添加autostart,执行命令提示未知子命令

解决Tauri执行tauri add autostart报错"unrecognized subcommand 'add'"的问题

问题原因

你遇到的报错是因为命令版本不匹配:tauri add是Tauri v2.x的专属命令,如果你当前使用的是Tauri v1.x版本,执行这个命令就会报错。

解决方案

第一步:确认你的Tauri版本

执行以下命令查看当前CLI版本:

npx tauri --version

针对Tauri v1.x版本

v1.x版本需要使用plugin add子命令来安装插件,而非直接add:

npx tauri plugin add autostart

或者手动完成配置:

  1. 在src-tauri/Cargo.toml中添加插件依赖:
    [dependencies]
    tauri-plugin-autostart = "0.1"
    
  2. 在src-tauri/src/main.rs中注册插件:
    fn main() {
        tauri::Builder::default()
            .plugin(tauri_plugin_autostart::init())
            .run(tauri::generate_context!())
            .expect("运行Tauri应用出错");
    }
    
  3. 前端代码中调用自启API(示例):
    import { enable, disable, isEnabled } from '@tauri-apps/plugin-autostart';
    
    // 开启开机自启
    await enable();
    // 关闭开机自启
    await disable();
    // 检查自启状态
    const isAutoStart = await isEnabled();
    

针对Tauri v2.x版本

如果确认是v2.x版本仍报错,尝试以下操作:

  1. 确保Tauri CLI已更新到最新版:
    npm install @tauri-apps/cli@latest --save-dev
    
  2. 直接执行npx tauri add autostart,而非通过npm run tauri(避免package.json中脚本配置异常)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 11:57:13