New to Angular, I have been experimenting with the installed node modules and their invocation in a data.service.ts file. All of the code below works just fine!
var isWindows = require('is-windows');
console.log("Is this windows? " + isWindows());
var builder = require('xmlbuilder');
var xml = builder.create('root')
.ele('xmlbuilder')
.ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
.end({ pretty: true});
console.log(xml);
var parseString = require('xml2js').parseString;
var xml = "<root>Hello xml2js!</root>"
parseString(xml, function (err, result) {
console.log(result);
});
The function I really need is the more complex xml2json function. This has a directory amongst my node_modules. When I add this line to the code (as per the documentation for this function):
var parser = require('xml2json');
ALL of the require statements are flagged as errors by the compiler!
ERROR in src/app/data.service.ts(45,20): error TS2304: Cannot find name 'require'. src/app/data.service.ts(48,18): error TS2304: Cannot find name 'require'. src/app/data.service.ts(55,22): error TS2304: Cannot find name 'require'.
If I try to declare this function via an import statement, that works UNTIL I add code to try to invoke the function -- at which time I get the same errors.
I notice the directory structure of the xml2json node is more complex than many others having a /bin, /lib and even a /node-modules (1 entry hoek) and perhaps my require statement is too simple.
These error messages seem to be fairly common in Angular, but none of the questions posted seem to be my exact problem. It seems that the require statement fails in some way when trying to acquire the xml2json resource, and that immediately impacts the other 'require' statement.
In my package.json file dependencies this node is listed as:
"xml2json": "^0.11.2",
Any guidance will be appreciated!