After creating a new Cordova project in Eclipse (Mars) when I click Finish, it starts adding platform to my app but ends up throwing the following error and the platform is not added:
X:\CordovaWorkspace\DemoProject>cordova prepare Discovered platform
"[email protected]" in config.xml. Adding it to
the project Adding android project... Running command: cmd "/s /c
"C:\Users\XYZ\.cordova\lib\android\cordova\5.3.0-nightly.2016.7.6.103e1e8d\bin\create.bat
X:\CordovaWorkspace\DemoProject\platforms\android demo.project "Demo
Project" --cli"" module.js:327
throw err;
^
Error: Cannot find module 'sax'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\XYZ\.cordova\lib\android\cordova\5.3.0-nightly.2016.7.6.103e1e8d\node_modules\elementtree\lib\parsers\sax.js:3:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17) Error: cmd: Command failed with exit code 1 Error: No platforms added to this project. Please use
`cordova platform add <platform>`.
X:\CordovaWorkspace\DemoProject>exit
How can it be resolved.
try to manually resolve the sax requirement by downloading the sax module and placing it in a folder called sax.
or use npm install
in case you don't find the sax mmodule in the internet you can create sax.js in your node-elementtree/lib/parsers/sax.js and put this code below:
var util = require('util');
var sax = require('sax');
var TreeBuilder = require('./../treebuilder').TreeBuilder;
function XMLParser(target) {
this.parser = sax.parser(true);
this.target = (target) ? target : new TreeBuilder();
this.parser.onopentag = this._handleOpenTag.bind(this);
this.parser.ontext = this._handleText.bind(this);
this.parser.oncdata = this._handleCdata.bind(this);
this.parser.ondoctype = this._handleDoctype.bind(this);
this.parser.oncomment = this._handleComment.bind(this);
this.parser.onclosetag = this._handleCloseTag.bind(this);
this.parser.onerror = this._handleError.bind(this);
}
XMLParser.prototype._handleOpenTag = function(tag) {
this.target.start(tag.name, tag.attributes);
};
XMLParser.prototype._handleText = function(text) {
this.target.data(text);
};
XMLParser.prototype._handleCdata = function(text) {
this.target.data(text);
};
XMLParser.prototype._handleDoctype = function(text) {
};
XMLParser.prototype._handleComment = function(comment) {
};
XMLParser.prototype._handleCloseTag = function(tag) {
this.target.end(tag);
};
XMLParser.prototype._handleError = function(err) {
throw err;
};
XMLParser.prototype.feed = function(chunk) {
this.parser.write(chunk);
};
XMLParser.prototype.close = function() {
this.parser.close();
return this.target.close();
};
exports.XMLParser = XMLParser;