What's proper way to access assets in expo?
I tried this:
await Asset.loadAsync(require('file:///assets/data/catalog.json'));
Error:
Unable to resolve "file:///assets/data/catalog.json"
Then I tried this:
await Asset.loadAsync(require('../../../assets/data/catalog.json'));
Error:
Module "[object Object]" is missing from the asset registry
Then I tried this:
await Asset.loadAsync('../../../assets/data/catalog.json');
Error:
Error: Unable to download file: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSErrorFailingURLStringKey=../../../assets/data/catalog.json, NSErrorFailingURLKey=../../../assets/data/catalog.json, _NSURLErrorRelatedURLSessionTaskErrorKey=("BackgroundDownloadTask <4AFE570E-3E85-4D12-B9F1-A0C14DA846D0>.<1>"), _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundDownloadTask <4AFE570E-3E85-4D12-B9F1-A0C14DA846D0>.<1>, NSLocalizedDescription=unsupported URL}
You need to add them to metro-config.js first and exclude json from sourceExts as well
config.resolver.assetExts.push("json");
config.resolver.sourceExts = config.resolver.sourceExts.filter(
(ext) => ext !== "json"
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With