Hello! New to RedwoodJS and loving it so far Can’t seem to find an answer to this question and hoping someone here can point me in the right direction.
I can’t import a local JSON file and get the error:
Error: Cannot find module 'xxx.json' in the dev terminal
I’ve added the
"resolveJsonModule": true, setting to
compilerOptions block in
tsconfig which got rid of ts error in my editor but still get the above error in the terminal.
Thanks in advance!
Welcome to the community!
It would be helpful if you had a reproduction or more information for the community to help you with this.
In particular we’d need to know:
- are you importing JSON on the web or API side?
- where is your JSON file located?
- does using a JS file help?
Here’s a guide to creating reproductions: https://github.com/redwoodjs/redwood/blob/main/CONTRIBUTING.md#creating-a-reproduction-to-include-with-issues
Thanks for the reply Danny, here is more info regarding my question:
- I am trying to use JSON files on the API side
- My JSON files were located in a folder under the
src directory (I also tried outside of it)
- Using a JS file helps yes
This is not a blocker by any means for me. A portion of the data my app consumes doesn’t need to be stored in a database, these are the JSON files I’m storing locally. I ended up just storing and consuming them in the frontend. If it ever does grow to the point that I need to store them in a DB or the cloud I will, but for now I’m okay.
It would still be good to know if I could store them on the backend and serve them from an endpoint but no stress if it’s trouble.
Storing them as files locally is unlikely to work out in the long run - all depends how you are deploying ofcourse. One option is that you could store it as JSONB Working with Json fields (Concepts)
or upload them to something like S3, B2, etc.
The API side doesn’t currently support using JSON files directly - you’re right. Perhaps this is something we need to revisit!
Makes sense, thanks Danny!