Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read xml file(toolsbox.xml) in React typescript

I am unable to import xml file in tsx file, but in jsx file i can able to access that xml file

enter image description here

enter image description here

like image 916
Sagar Raviprolu Avatar asked Oct 18 '25 16:10

Sagar Raviprolu


1 Answers

You need to define a module for typescript to evaluate, otherwise it will try to look for something like toolbox.xml.ts.

Something along these lines in a file called XML.d.ts (for this placed in a folder @types in src):

declare module "*.xml" {
  const doc: any; // Change this to an actual XML type
  export default doc;
}

and add "typeRoots": ["src/@types", "node_modules/@types"] to your tsconfig.json (this makes typescript pick up the new typings file along with all installed types).

like image 83
Elias Schablowski Avatar answered Oct 20 '25 06:10

Elias Schablowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!