Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

包含fetch请求时 执行kraken 报错flutter: FormatException: Invalid empty scheme (at character 1) #827

Closed
jingsarah opened this issue Nov 2, 2021 · 2 comments

Comments

@jingsarah
Copy link

使用的 Kraken 版本 | What version of kraken are you using

0.8.4

重现步骤 | Steps To Reproduce

用vue开发kraken项目中涉及fetch请求时,执行npm run build 后,执行 kraken ./dist/js/app.js 报错, 用官网demo 和提供的fetch demo同样报错

企业微信截图_efc6803a-955a-4675-be62-a4d2450e7b86
flutter: FormatException: Invalid empty scheme (at character 1)
:///category
^

#0 _Uri._fail (dart:core/uri.dart:1538:5)
#1 new _Uri.notSimple (dart:core/uri.dart:1371:9)
#2 Uri.parse (dart:core/uri.dart:956:17)
#3 FetchModule._resolveUri (package:kraken/src/module/fetch.dart:35:22)
#4 FetchModule.invoke (package:kraken/src/module/fetch.dart:90:15)
#5 ModuleManager.invokeModule (package:kraken/src/module/module_manager.dart:65:19)
#6 invokeModule (package:kraken/src/bridge/from_native.dart:90:46)
#7 _invokeModule (package:kraken/src/bridge/from_native.dart:103:19)
#8 _FfiCallback_invokeModule (dart:ffi)
#9 FfiTrampoline (dart:ffi)
#10 evaluateScripts (package:kraken/src/bridge/to_native.dart:146:21)
#11 KrakenBundle.eval (package:kraken/src/launcher/bundle.dart:86:7)
#12 KrakenController.evalBundle (package:kraken/src/launcher/controller.dart:721:22)
#13 launch._initKrakenApp (package:kraken/src/launcher/launcher.dart:51:22)

#14 launch (package:kraken/src/launcher/launcher.dart:72:5)

重现代码 | Code example:
const data = {
username: 'kraken team',
};

fetch('http://example.com/post', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
})
.then(function(response) {
return response.json();
})
.then(function(data) {
// Server post response.
console.log(data);
});

预期结果 | Expected results:

实际结果 | Actual results:

@jingsarah jingsarah added the bug Something isn't working label Nov 2, 2021
@wssgcg1213
Copy link
Member

看起来是有一个 /category 的请求, 但是 baseUrl 是一个本地路径, 相对于这个路径解析, 所以没有 http 的 scheme

这种情况下需要使用完整 url 请求, 你写的重现代码不是引起报错的代码

@wssgcg1213 wssgcg1213 removed the bug Something isn't working label Nov 3, 2021
@jingsarah
Copy link
Author

看起来是有一个 /category 的请求, 但是 baseUrl 是一个本地路径, 相对于这个路径解析, 所以没有 http 的 scheme

这种情况下需要使用完整 url 请求, 你写的重现代码不是引起报错的代码
git clone https://github.com/openkraken/samples.git
cd ./demos/hello-vue 用vue demo 加上fetch请求跑同样会报错,如果去掉fetch请求就没问题,所以才怀疑是否是fetch的影响
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants