Jump to content

Hey there,
 

I need help in importing this JSON file to the Typescript file so I can work on it.

 

No matter what I do it keeps saying that the file does not exist and so on, I've even tried moving the JSON file so that it's in the same file as the TS file, double checked the name everything and it still won't work. From what I've seen, I can access the JSON file by the component.ts file with the same path etc, but if I try to import the JSON file into this smaller TS script, it just says that the file does not exist, even though it does.

Yes, I do have resolveJsonModule set to true, and esModuleInterop set to true as well.

 

Any help appreciated.

 

angularjsonimportissue.thumb.png.2561dd507a3c7cf6e6483b499ee49ad2.png

 

File structure:

image.png.1cea2e55d465f39ec88e96877d508e0f.png
 

How easy it should be:

https://medium.com/codeptivesolutions/how-to-import-json-file-in-angular-a2e012948479

Link to comment
https://linustechtips.com/topic/1611911-cannot-import-json-file-to-ts-file-angular/
Share on other sites

Link to post
Share on other sites

6 hours ago, Elijah Kamski said:

I can access the JSON file by the component.ts file with the same path etc, but if I try to import the JSON file into this smaller TS script, it just says that the file does not exist, even though it does.

Relative path issue. If react path are anything like php. The path for imports is relative to the parent script location, not from the child scripts location.

 

May be better to configure path aliases rather than rely relative paths? Makes paths to components alot clearer.

https://blog.logrocket.com/using-path-aliases-cleaner-react-typescript-imports/

 

 

Link to post
Share on other sites

  • 2 weeks later...
On 5/14/2025 at 2:15 PM, C2dan88 said:

Relative path issue. If react path are anything like php. The path for imports is relative to the parent script location, not from the child scripts location.

 

May be better to configure path aliases rather than rely relative paths? Makes paths to components alot clearer.

https://blog.logrocket.com/using-path-aliases-cleaner-react-typescript-imports/

 

 

Thanks, I'll look into this

My thing is using Angular, so hope this thing works out, will let you know if it does.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×