You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.
After running npm install.... and adding this in my service.ts: import * as xml2js from 'node_modules/xml2js';
It builds but I get this warning:
[ts] Could not find a declaration file for module 'node_modules/xml2js'...
Try 'npm install @types/xml2js' if it exists or add a new declaration (d.ts) file containing 'declare module 'xml2js';`
I did that and still get the same.
The text was updated successfully, but these errors were encountered:
The package is written in pure javascript, so there are no type definitions of toJson & toXml functions. That's why the compiler raises an error.
You can define a declaration module yourself (depends on tsconfig.json). For example, put the following file into types/xml2json.d.ts:
declare module 'xml2json'{exporttypeToJsonOptions={// Returns a Javascript object instead of a JSON stringobject: boolean;// Makes the JSON reversible to XMLreversible: boolean;// Makes type coercion. i.e.: numbers and booleans present in attributes and// element values are converted from string to its correspondent data types.// Coerce can be optionally defined as an object with specific methods of// coercion based on attribute name or tag name, with fallback to default coercion.coerce: boolean;// Sanitizes the following characters present in element values: < > ( ) # & " 'sanitize: boolean;// Removes leading and trailing whitespaces as well as line terminators in element values.trim: boolean;// XML child nodes are always treated as arrays NB: you can specify// a selective array of nodes for this to apply to instead of the whole document.arrayNotation: boolean;// Changes the default textNode property from $t to _t when option is set to true.// Alternatively a string can be specified which will override $t to what ever the string is.alternateTextNode: boolean;}exporttypeToXmlOptions={// Sanitizes the following characters present in element values: < > ( ) # & " 'sanitize: boolean;// Ignores all null valuesignoreNull: boolean;}exportfunctiontoJson(xml: string,options?: Partial<ToJsonOptions>): string|objectexportfunctiontoXml(json: string,options?: Partial<ToXmlOptions>): string}
I'm trying to return a SOAP response in Angular 6.0 httpClient typescript, so I need to convert XML to JSON.
How do I used NodeRequire in typescript ?
I'm trying to do this:
eturn this.http.post(environment.engageServiceUrl + '?op=RetrieveEmployees', soapPayload, httpOptions) .map(data => { var xmlJsn = require('node_modules/xml2js'); console.log(data); },
but it won't build.
I've tried to follow this example:
https://stackoverflow.com/questions/36368405/how-to-parse-xml-in-angular-2
After running npm install.... and adding this in my service.ts:
import * as xml2js from 'node_modules/xml2js';
It builds but I get this warning:
[ts] Could not find a declaration file for module 'node_modules/xml2js'...
Try 'npm install @types/xml2js' if it exists or add a new declaration (d.ts) file containing 'declare module 'xml2js';`
I did that and still get the same.
The text was updated successfully, but these errors were encountered: