Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to Asset in Expo

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}

like image 885
rnofenko Avatar asked Oct 15 '25 08:10

rnofenko


1 Answers

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"
);
like image 93
Archimedes Trajano Avatar answered Oct 19 '25 10:10

Archimedes Trajano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!