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.

1
  • You can try using const myData = require('../staticData/data.json'); Commented Mar 19, 2020 at 12:25

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, it seems react native doesn't support .json extension
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 stackoverflow.com/questions/29452822/…, and have some insights.
Thank you I will take a look

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.