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

创建表单时无法生成Qwik QRL的问题求助

Qwik表单报错“Cannot create a Qwik QRL when creating a form”的解决思路

问题场景

以下代码在Chrome Canary 128.0.6582.0中运行时,浏览器控制台抛出“Cannot create a Qwik QRL when creating a form”错误:

import { component$ } from "@builder.io/qwik";
import { routeAction$, Form } from "@builder.io/qwik-city";

export const useAccountCreation = routeAction$(async () => ({
  success: true,
}));

export default component$(() => {
  const action = useAccountCreation();

  return (
    <Form action={action}>
      <label>
        Your name
        <input type="text" name="name" />
      </label>
      <button type="submit">Sign up</button>
    </Form>
  );
});

渲染后的form标签中,on:submit属性包含编码后的Windows路径(反斜杠被转义为%5C):

<form action="?qaction=EF0CVuuKE74" preventdefault:submit="" method="post" on:submit="//%40fs/path%5Cnode_modules%5C%40builder.io%5Cqwik-city/routeactionqrl_action_submit_a5bzc7wo00a.js?_qrl_parent=path%5Cnode_modules%5C%40builder.io%5Cqwik-city%5Cindex.qwik.mjs#routeActionQrl_action_submit_A5bZC7WO00A[0 1 2 3]" q:key="0F_0" q:id="7">
    <label data-qwik-inspector="routes/test/index.tsx:13:7">
        Your name
        <input type="text" name="name" data-qwik-inspector="routes/test/index.tsx:15:9"> 
    </label>
    <button type="submit" data-qwik-inspector="routes/test/index.tsx:17:7">Sign up</button>
</form>

经测试,在控制台执行new URL("%5C")会复现相同错误,确认是路径中的%5C编码字符导致QRL创建失败。

环境版本:

  • @builder.io/qwik: ^1.6.0
  • @builder.io/qwik-city: ^1.6.0

解决思路

  • 优化项目路径:将项目迁移到路径更简洁的目录下,避免嵌套过深;同时确保路径中使用正斜杠(/)代替Windows默认的反斜杠(\),从源头上减少编码问题。
  • 升级依赖版本:Qwik后续版本可能修复了Windows路径编码的兼容问题,尝试升级@builder.io/qwik和@builder.io/qwik-city到最新稳定版,比如1.8.x系列。
  • 调整开发环境配置:
    • 若使用Vite,在vite.config.ts中配置server.fs.strict: false,或者通过server.fs.allow指定允许访问的目录,可能缓解路径解析异常。
    • 切换到WSL(Windows子系统Linux)环境开发,Linux系统使用正斜杠路径,彻底规避反斜杠编码问题。
  • 临时应急方案:(不推荐用于生产)手动修改Qwik-City相关源码,在生成QRL路径时将反斜杠替换为正斜杠后再进行URL编码。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 11:49:54