Home > Mobile >  How to import a static local json file in react?
How to import a static local json file in react?

Time:10-12

I am trying import a static local json file in my .ts like

import json from '../../markets/localization/MktIn.json

On run time, I get an error that module is not found. I am using webpack 4.41 and React 16.13 and json-loader 0.5.7. On my research, I see that I do not need to add any specific webpack config on versions >= 2.0 and can directly import. Can someone provide any pointers on this? I have tried couple of hours trying out all solutions from previous posts.

CodePudding user response:

I think you should try to use this line of code

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

And also mind your relative path. Make sure it was the correct path

Here was the detail instruction related this

Hope it was help you

Thank you

CodePudding user response:

javascript native can import js and json file。so you should input the wrong path,review your path ?

  • Related