Zydnar
Zydnar

Reputation: 1502

Importing JSON file in ReactXP

I have strange problem possibly bug with importing JSON file as object into my application. I do have:

"compilerOptions": {
    "resolveJsonModule": true,
    "esModuleInterop": true,
}

Looking at the s̶o̶u̶r̶c̶e̶ ̶a̶n̶d̶ source maps JSON is being imported and even when I look at debugger: enter image description here

But as you see debugger is able to see contents of this var/JSON while app claims it's undefined. Can it be building cache problem? I import JSON file like:

import  * as eventsDB from './events.json';

and for debugging purpose I export it like this:

export const jsonDB = eventsDB;

EDIT: After checking carefuly build whole reducer where I import and export JSON was ommited but for some reason everything was in Source-Maps, I'm currently searching for possible reason.

Upvotes: 0

Views: 40

Answers (1)

Zydnar
Zydnar

Reputation: 1502

Guys I've located the problem. I think this might be helpful, so I want to share the solution. As I said in reducer named events (file name events.ts) I've imported the JSON:

import  * as eventsDB from './events.json';

And some of you might already noticed the problem. Even when I included the extension, for some reason there was name conflict so under events reducer

import  events from '../reducers/events';

I actually had the JSON. And under JSON I had undefined. Still the mistery is why debugger saw the contents of the variable correctly.

Upvotes: 0

Related Questions