jsreport beforeRender problem with Error: Unable to find module foo
-
What is in your
foo
module?
We throw the "unable to find module" every time when therequire('foo')
crashes.
Maybe it is found, but there is some error inside.
It is likely the issue because therequire('console')
didn't fail for you.
-
Hi @jan_blaha , "foo" is a directory that contain some custom scripts and package.json .
here is my directory structure:/opt
/jsreport
/node_modules
/foo
index.js
package.json
/node_modules
/lib
couchbase-ds.js
surveyReport.jsand package.json is as follows:
{ "name": "foo", "main": "index.js", "dependencies": { "couchbase": ">= 2.0.7", "esl": ">= 3.0.0", "hiredis": ">= 0.3.0", "modesl": ">= 1.1.3", "mysql": ">= 2.6.2", "redis": ">= 0.12.1", "ssh2": ">= 0.4.13", "utf8": "^2.1.1" } }
and index.js is here:
var ods = module.exports = {} ods.CouchbaseDS = require("./lib/couchbase-ds.js").CouchbaseDS; ods.SurveyReport = require("./lib/surveyReport.js").SurveyReport;
It's important that main script in surveyReport.js executes without any error and returns desired data structure,
when i run it as test script on the same machine. also it seems that there isn't any faulty code in it.
-
Hi @jan_blaha , in conjunction with your suggestion about "foo", i tried to test some simple code instead of "couchbase-ds.js".
Unfortunately the result is not changed and i see the same error again: "Unable to find module foo".here is the sample code in :
couchbase-ds.jsvar CouchbaseDS = exports.CouchbaseDS = function(context) { this.bucket = null; } CouchbaseDS.prototype.open = function(bucket_name, cb) { return cb && cb(null); } CouchbaseDS.prototype.queryLog = function(key, cb) { var now = new Date(); var al = { days: [], queue: { name: key.queue, reportDate: formatDate(now.valueOf()), startDate: key.interval_start != undefined ? formatDate(key.interval_start) : '', endDate: key.interval_end != null ? formatDate(key.interval_end) : '' } }; return cb && cb(null, al); } CouchbaseDS.prototype.queryBriefActivityLog = function(key, cb) { var now = new Date(); var al = { days: [], entity: { name: key.queue ? key.queue : key.user[0], reportDate: formatDate(now.valueOf()), startDate: key.interval_start != undefined ? formatDate(key.interval_start) : '', endDate: key.interval_end != null ? formatDate(key.interval_end) : '' } }; return cb && cb(null, al); } function formatDate(x) { var d = new Date(x); return [ d.getFullYear(), d.getMonth()+1, d.getDate() ].join('/') + ' ' + [ d.getHours(), d.getMinutes(), d.getSeconds() ].join(':'); }
Therefore i think that the error is not depends on scripts. Are you agree? What can I check?
Thanks in advanced.
-
Hi @jan_blaha again, a point that i remembered now is my code works fine on another server and the only difference is
that node version there is v4.4.7 but here it is v8.14.1 , although I have installed foo with npm install .. that make the dependencies
up to date . Jsreport version is "jsreport 1.4.0 production" on both servers.
Can this difference be the source of error? although as i mentioned in last posts the script executes on this machine without error!!!!
-
Hi @jan_blaha , in conjunction with your suggestion about "foo", i tried to test some simple code instead of "couchbase-ds.js".
Unfortunately the result is not changed and i see the same error again: "Unable to find module foo".I am getting a bit lost in it. So if you put to foo just a dummy index.js. It crashes also?
I don't know if we are solving the problem that the foo is not found or it has an actual error.that node version there is v4.4.7 but here it is v8.14.1 ,
Well your script can use some features that are not supported in 4.4.7 and crash.
-
Btw you should later check this thread. There is a bug in couchbase node client which can cause the queries hanging in our sandbox.
https://forum.jsreport.net/topic/819/unable-to-fetch-data-from-remote-server-in-beforerender/6
-
Hi @jan_blaha and thank you for help. I've removed index.js from foo directory, so there is no relation to my custom code
and tried to test again, but the error is still and is as expected "Unable to find module foo".
It seems as i commented in "berforeRender", that error occurred in second line of code:var ds = require('foo');
and none of my script does not executed. Thus can I explain why after removing index.js
there is no difference in error in both cases. I think actually jsreport can not find foo. In addition
the error log that i included in first post shows thatsearch path: foo foo /opt/jsreport/foo ....
jsreport searches foo in /opt/jsreport directory that is false, it must be /opt/jsreport/node_modules.
Is it correct? Have I understand correctly?regards
-
Hi @jan_blaha , i tried everything that I've known and now I've confused. Are you recommend me to reinstalling jsreport from scratch?
I think probably there was a mistake in installing or configuring jsreport!
-
Hi @jan_blaha and thank you for help. I've removed index.js from foo directory, so there is no relation to my custom code
You removed the index.js but kept the package.json? In that case the require('foo') still crashes.
Please make sure your package actually works when you call require('foo') from theserver.js
file in the application root.I think actually jsreport can not find foo. In addition
the error log that I included in first post shows thatThese paths are actually correct. I have the same. You get exactly this error if you put something like
throw new Error('xxx')
to theindex.js
file.So far I still think your
foo
package is for some reason not working properly.
-
Hi @jan_blaha , Thanks a lot for your recommendations, finally I found the crashes module, that used a postgres without installing it
on this server. You save my life!!! I've completely confused
Thanks again