'Importing Bin file in Expo

I have tried adding metro.config.js as


const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.assetExts.push('bin');

module.exports = defaultConfig;

But still it gives me error of unable to resolve module.

I am working in ML project

MY import code for model.json and shards.bin looks like this

    const modelJSON = require('../../../assets/NEWJSON2/model.json');

    const modelWeights = require('../../../assets/group1_shards.bin');

    let model = await tf.loadGraphModel(bundleResourceIO(modelJSON, modelWeights));


Solution 1:[1]

Update: I changed my metro config,

const { getDefaultConfig } = require('metro-config');
module.exports = (async () => {
  const defaultConfig = await getDefaultConfig();
  const { assetExts } = defaultConfig.resolver;
  return {
    resolver: {
      // Add bin to assetExts
      assetExts: [...assetExts, 'bin'],
    }
  };
})();

I imported the json and weights as,

      const modelJSON = require('../../../assets/model.json');

      const modelWeights = await require('../../../assets/group1_shards.bin');

      let model = await tf.loadLayersModel(bundleResourceIO(modelJSON, modelWeights));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ankit Pradhan