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

Flutter Web报错指向JS文件而非Dart文件的调试配置问题咨询

Flutter Web 报错仅指向JS文件不映射Dart源文件解决方案

你遇到的错误日志如下:

Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
This app is linked to the debug service: ws://127.0.0.1:63045/gOvW2paMrLg=/ws
Debug service listening on ws://127.0.0.1:63045/gOvW2paMrLg=/ws

 Running with sound null safety 
Debug service listening on ws://127.0.0.1:63045/gOvW2paMrLg=/ws
Error: Invalid argument(s): A value must be provided. Supported values: 0, 1
    at Object.throw_ [as throw] (http://localhost:53846/dart_sdk.js:5061:11)
    at Object._$36enumDecode [as _$enumDecode] (http://localhost:53846/packages/web_app/core/models/pessoa/pessoa.dart.lib.js:482:17)
    at Object._$36PessoaFromJson [as _$PessoaFromJson] (http://localhost:53846/packages/web_app/core/models/pessoa/pessoa.dart.lib.js:473:54)
    at Function.fromJson (http://localhost:53846/packages/web_app/core/models/pessoa/pessoa.dart.lib.js:375:21)
    at http://localhost:53846/packages/web_app/repository/pessoa_repository.dart.lib.js:60:193
    at repository.RepositoryGetter.new.getRecurso (http://localhost:53846/packages/web_app/repository/repository.dart.lib.js:33:18)
    at getRecurso.next (<anonymous>)
    at http://localhost:53846/dart_sdk.js:38640:33
    at _RootZone.runUnary (http://localhost:53846/dart_sdk.js:38511:59)
    at _FutureListener.thenAwait.handleValue (http://localhost:53846/dart_sdk.js:33713:29)
    at handleValueCallback (http://localhost:53846/dart_sdk.js:34265:49)
    at Function._propagateToListeners (http://localhost:53846/dart_sdk.js:34303:17)
    at _Future.new.[_completeWithValue] (http://localhost:53846/dart_sdk.js:34151:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:53846/dart_sdk.js:34172:35)
    at Object._microtaskLoop (http://localhost:53846/dart_sdk.js:38778:13)
    at _startMicrotaskLoop (http://localhost:53846/dart_sdk.js:38784:13)
    at http://localhost:53846/dart_sdk.js:34519:9

修复步骤

1. 确认运行模式未添加禁用源映射的参数

debug模式默认开启源映射映射到Dart源文件,需要排查:

  • 运行时不要添加--release、--profile、--no-source-maps参数
  • 打开Android Studio的运行配置(Run > Edit Configurations),确认你的Flutter Web运行项没有额外添加上述禁用参数

2. 修复2.5.x版本已知bug

你使用的Flutter 2.5.2稳定版存在官方已知的Web调试源映射失效问题,优先选择升级到最新稳定版:

flutter channel stable
flutter upgrade

如果项目暂时不能升级版本,在运行配置的Additional arguments栏手动添加以下参数:

--source-maps --debug

保存配置后重新运行项目即可生效。

3. 浏览器端配置(Chrome控制台查看日志场景)

如果直接在Chrome开发者工具中查看日志,需要确认源映射开关已开启:

  • 打开Chrome DevTools,按F1打开设置页面
  • 在Sources分类下,勾选Enable JavaScript source maps选项

当前问题快速定位方法

从现有日志已经可以定位到错误根源:pessoa.dart文件的枚举解析逻辑收到了超出0、1范围的枚举值,你可以先检查Pessoa模型的json_serializable解析代码,给枚举添加默认值或者新增未知值处理逻辑,即可先解决本次报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 15:57:03