nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
116 stars 52 forks source link

fs.readFileSync() is not a function #57

Closed prasanthmpr closed 7 years ago

prasanthmpr commented 7 years ago

After installing and including the node-ews in my ionic project, getting the error as " TypeError: Cannot read property 'prototype' of undefined" in graceful.js.

Anyone have come across this issue?

kcastrotech commented 7 years ago

Can you include the full error message? It should indicate which line in graceful.js has the issue.

But ultimately what that error means is that on whatever line it references, there is something like "myvariable.prototype" and "myvariable" is undefined. You'll need to check further up in the code to ensure that "myvariable" is somehow defined first like "var myvariable = {};" or "var myvariable = function(){};".

kcastrotech commented 7 years ago

For example, if I simply had:

//Start of script file
LKE.prototype.init = function(){
    if(this.config.debug) console.log('Initializing Exchanger');
    this.clients = {
        ews:new EWS(this.config.ews.username, this.config.ews.password, this.config.ews.host,this.config.ews.options)
    };
}

I would get the same error because "LKE" doesn't exist prior to me calling "LKE.prototype". The correct usage is:

//Start of script file
var EWS = require('node-ews'),
    when = require('when'),
    util = require('util'), //npm install util
    _ = require('lodash');

//Declare "LKE" as a custom function.
var LKE = function(config){
    this.config = config || {};
    this.clients = {};
    this.init();
}

//Here I'm expanding on "LKE" by defining an init function
LKE.prototype.init = function(){
    if(this.config.debug) console.log('Initializing Exchanger');
    this.clients = {
        ews:new EWS(this.config.ews.username, this.config.ews.password, this.config.ews.host,this.config.ews.options)
    };
}

For a good definition of using prototype vs declaring:

var myfunction = function(){
  this.newfunction = function(){
  ...
  }
}

Check out: https://stackoverflow.com/questions/310870/use-of-prototype-vs-this-in-javascript

prasanthmpr commented 7 years ago

var fs$ReadStream = fs.ReadStream ReadStream.prototype = Object.create(fs$ReadStream.prototype) ReadStream.prototype.open = ReadStream$open

var fs$WriteStream = fs.WriteStream WriteStream.prototype = Object.create(fs$WriteStream.prototype) WriteStream.prototype.open = WriteStream$open

/FS is not currently in use. So, i have used fs-extra instead of FS module. While i am changing var fs=require('fs') to var fs= require('fs-extra') i am getting this prototype error. /

kcastrotech commented 7 years ago

What is the full error message?

prasanthmpr commented 7 years ago

After installing and including const EWS = require('node-ews') in my .ts file, i am getting this error

core.es5.js:1084 ERROR Error: Uncaught (in promise): TypeError: fs.readFileSync is not a function TypeError: fs.readFileSync is not a function at Object. (WSSecurityCert.js:8) at Object. (WSSecurityCert.js:78) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at Object. (index.js:9) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at Object. (soap.js:11) at Object. (soap.js:94) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at Object. (index.js:3) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at Object. (WSSecurityCert.js:8) at Object. (WSSecurityCert.js:78) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at Object. (index.js:9) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at Object. (soap.js:11) at Object. (soap.js:94) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at Object. (index.js:3) at webpack_require (bootstrap 8b2020833102c0a181d3:54) at c (polyfills.js:3) at Object.reject (polyfills.js:3) at NavControllerBase._fireError (nav-controller-base.js:322) at NavControllerBase._failed (nav-controller-base.js:310) at nav-controller-base.js:365 at t.invoke (polyfills.js:3) at Object.onInvoke (core.es5.js:4149) at t.invoke (polyfills.js:3) at r.run (polyfills.js:3) at polyfills.js:3

prasanthmpr commented 7 years ago

As FS is not currently in use, i have changed var fs = require('fs'); to var fs = require('fs-extra'); in WSSecurityCert.js. Then i am getting this error.

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'prototype' of undefined TypeError: Cannot read property 'prototype' of undefined at patch (graceful-fs.js:166) at Object. (graceful-fs.js:27) at Object. (graceful-fs.js:262) at webpack_require (bootstrap ddd5e8e7a66c686d5db7:54) at Object. (index.js:4) at webpack_require (bootstrap ddd5e8e7a66c686d5db7:54) at Object.module.exports (index.js:8) at webpack_require (bootstrap ddd5e8e7a66c686d5db7:54) at Object. (WSSecurityCert.js:3) at Object. (WSSecurityCert.js:78) at patch (graceful-fs.js:166) at Object. (graceful-fs.js:27) at Object. (graceful-fs.js:262) at webpack_require (bootstrap ddd5e8e7a66c686d5db7:54) at Object. (index.js:4) at webpack_require (bootstrap ddd5e8e7a66c686d5db7:54) at Object.module.exports (index.js:8) at webpack_require (bootstrap ddd5e8e7a66c686d5db7:54) at Object. (WSSecurityCert.js:3) at Object. (WSSecurityCert.js:78) at c (polyfills.js:3) at Object.reject (polyfills.js:3) at NavControllerBase._fireError (nav-controller-base.js:322) at NavControllerBase._failed (nav-controller-base.js:310) at nav-controller-base.js:365 at t.invoke (polyfills.js:3) at Object.onInvoke (core.es5.js:4149) at t.invoke (polyfills.js:3) at r.run (polyfills.js:3) at polyfills.js:3 defaultErrorLogger @ core.es5.js:1084

kcastrotech commented 7 years ago

That seems to be a graceful-fs or fs-extra issue. I suggest you take a look at this thread (https://github.com/jprichardson/node-fs-extra/issues/261).

kcastrotech commented 7 years ago

Just realized that this is part of #59 whereby I can see that this is for an Ionic project. As this is not a node-ews issue I'm going to close this thread. A link to a possible solution was posted on the other thread which I will leave open for further discussion.