4

I am using React Native version 0.59.4. I created a file data.json

But when I import this file like this

import myData from '../staticData/data.json';

I get this error Bundle failed: Could not resolve module ... and I made sure the path is correct

I also tried removing the extension but no change

I tried almost every solution here.

Is there anything more that I can try?

EDIT I tried changing the extension from .json to .js and in that file I added export default { // json } and it worked like a charm.

Amine
  • 2,241
  • 2
  • 19
  • 41

1 Answers1

2

Well, you are doing it right, I think you are messing with the path. Are you sure that`s the right path, and how organized are your folders ???? another way to do that is to use the old JS way

const customData = require('./customData.json');
  • Thank you, it seems react native doesn't support .json extension – Amine Mar 19 '20 at 12:48
  • 1
    Look I'm pretty sure that supports it, but I'm not aware of the system that you are using your npm version and so on. I think you can look at here https://stackoverflow.com/questions/29452822/how-to-fetch-data-from-local-json-file-on-react-native, and have some insights. – guilherme victor ramalho natal Mar 19 '20 at 12:54
  • Thank you I will take a look – Amine Mar 19 '20 at 12:56