I am using MEAN.JS for developing a web app, but for some reason after I made few changes, well mostly copied and paste new modules into the app I see the error as below:
error: uncaughtException: require(...).invokeRolesPolicies is not a function
I dont know why is this happening, anyone has any clue how to fix this?
This is the whole error message:
TypeError: require(...).invokeRolesPolicies is not a function
at C:\oferdo\oferdo\config\lib\express.js:180:39
at Array.forEach (native)
at Object.module.exports.initModulesServerPolicies (C:\oferdo\oferdo\config\lib\express.js:179:32)
at Object.module.exports.init (C:\oferdo\oferdo\config\lib\express.js:252:8)
at C:\oferdo\oferdo\config\lib\app.js:29:23
at C:\oferdo\oferdo\config\lib\mongoose.js:36:15
at C:\oferdo\oferdo\node_modules\mongoose\lib\connection.js:284:19
at open (C:\oferdo\oferdo\node_modules\mongoose\lib\connection.js:511:17)
at C:\oferdo\oferdo\node_modules\mongoose\lib\connection.js:518:7
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\db.js:1504:5
at handleCallback (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\utils.js:96:12)
at _callback (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\db.js:1420:5)
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\lib\db.js:1463:7
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:1416:5
at finish (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:157:16)
at handleEnd (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:170:7)
at C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:264:17
at commandCallback (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:1194:9)
at Callbacks.emit (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:119:3)
at null.messageHandler (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:358:23)
at Socket. (C:\oferdo\oferdo\node_modules\mongoose\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.js:292:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:531:20)
Actually, this is nothing to do with incorrectly named files.
You need to make sure that you have the invokeRolesPolicies function defined within your policies file. The minimum required is:
'use strict';
var acl = require('acl');
acl = new acl(new acl.memoryBackend());
exports.invokeRolesPolicies = function () {};
The reason why is that the express.js lib defined in mean.js assumes this is set, and tries to call it, hence the error.
You'll get this error if you have an incorrectly named file under your module's server > policies directory, so check there for any inconsistently named files.
EDIT
I see now that it's not the naming of the file but if you have a file in the policies directory that doesn't contain this method, it will produce this error. In my case I had temporarily commented out the code in a file in this directory in preparation for removal.
Related
I'm setting up an api application based on NodeJS and the ORM Sequelize. Everything work fine on my local computer (Windows), but when I want to install this app on a AWS EC2 Linux Instance, I'm encountering this error at the launch of the app :
internal/buffer.js:53
throw new ERR_OUT_OF_RANGE(type || 'offset',
^
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 5. Received 9
at boundsError (internal/buffer.js:53:9)
at Uint8Array.readUInt32LE (internal/buffer.js:109:5)
at Packet.readInt32 (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/packets/packet.js:103:24)
at Function.fromPacket (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/packets/handshake.js:59:32)
at ClientHandshake.handshakeInit (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/commands/client_handshake.js:92:40)
at ClientHandshake.execute (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/commands/command.js:39:22)
at Connection.handlePacket (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/connection.js:449:32)
at PacketParser.Connection.packetParser.p [as onPacket] (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/connection.js:72:12)
at PacketParser.executeStart (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/home/ec2-user/live/CodexAvatarAPI/node_modules/mysql2/lib/connection.js:79:25)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
I've done some research but found nothing useful for now. To my understanding (i'm a beginner with node), the problem seems to be more in the mysql2 component than in the core of NodeJS itself, but I'm not sure where to search exactly.
This error happen juste before synchronizing the database structure with what has been defined in the code. Normally I have to see database update at this point.
I can't figure out what I've done to mess up Jasmine.
Here's a link to the repo I'm working on:
https://github.com/bryanbeus/04-09-bloccit/tree/v0.1.3
The problem is somehow related to the files /spec/integration/flairs_spec.js, /spec/integration/post_spec.js, and probably more.
The problem can be seen when running a command like npm test. I get the following result:
04-09-bloccit#1.0.0 test /home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit
export NODE_ENV=test && jasmine
npm ERR! Test failed. See above for more details.
It used to be that this ERR would only occur if I had an non-compilable error somewhere in my code. (For example, a simple thing like ; out of place, or an improper use of this.)
Recently, I've heard from someone else that this type of failure for Jasmine isn't normal. Usually, if there's a problem in the code, Jasmine is still supposed to say something. ?
Whatever the problem is, it is now spreading to general usage.
I'm trying to call the server npm module for a test with this command:
const server = require("../../src/server");
If that line is anywhere in my files, the entire Jasmine test fails in the exact same manner. (npm ERR... and no other details.)
If I run npm test /spec/integration/flairs_spec.js with that call to server active, the test fails in the npm ERR... manner.
However, if I comment out the call to server, then Jasmine at least runs. It returns this error:
....................
Started
F
Failures:
1) routes : flairs GET /topics/:topicId/posts/:postId/flairs/new should render a new flair form
Message:
Expected Error: connect ECONNREFUSED 127.0.0.1:3000 to be null.
Stack:
Error: Expected Error: connect ECONNREFUSED 127.0.0.1:3000 to be null.
at
at Request.request.get [as _callback] (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/spec/integration/flairs_spec.js:57:21)
at self.callback (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:186:22)
at Request.emit (events.js:160:13)
at Request.onRequestError (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:878:8)
at ClientRequest.emit (events.js:160:13)
at Socket.socketErrorListener (_http_client.js:389:9)
at Socket.emit (events.js:160:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
Message:
Expected undefined to contain 'New Flair'.
Stack:
Error: Expected undefined to contain 'New Flair'.
at
at Request.request.get [as _callback] (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/spec/integration/flairs_spec.js:58:22)
at self.callback (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:186:22)
at Request.emit (events.js:160:13)
at Request.onRequestError (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:878:8)
at ClientRequest.emit (events.js:160:13)
at Socket.socketErrorListener (_http_client.js:389:9)
at Socket.emit (events.js:160:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
1 spec, 1 failure
Finished in 0.399 seconds
npm ERR! Test failed. See above for more details.
.......
So, removing the server call at least lets Jasmine run.
Any help on this is appreciated. Thank you for helping a novice programmer.
I found the source of the error.
Using git diff v0.1.2..v0.1.3 I was able to see the differences between the last working branch, and the current one.
From here, I saw that in db/src/controllers/flairController.js I had placed this in the controller for the flair object:
const flairQueries = require("./db/queries.flairs.js");
The problem with that is that the directory isn't correct. I replaced it with this:
const flairQueries = require("../db/queries.flairs.js");
After this, the Jasmine test suite worked.
I understand that this means that the controller couldn't load properly. The full understanding of this is still elusive, so if anyone has time to try to explain, I would appreciate it. Otherwise, we can consider this question closed. Thanks!
Failed to invoke successfully :: TypeError: Cannot read property 'getConnectivityState' of undefined
/opt/share/hyperledger/node_modules/fabric-client/lib/EventHub.js:355
if(self._stream) state = self.stream.call.channel.getConnectivityState();
^
TypeError: Cannot read property 'getConnectivityState' of undefined
at ClientDuplexStream.<anonymous> (/opt/share/hyperledger/node_modules/fabric-client/lib/EventHub.js:355:56)
at emitOne (events.js:116:13)
at ClientDuplexStream.emit (events.js:211:7)
at ClientDuplexStream._emitStatusIfDone (/opt/share/hyperledger/node_modules/grpc/src/client.js:236:12)
at ClientDuplexStream._readsDone (/opt/share/hyperledger/node_modules/grpc/src/client.js:201:8)
at /opt/share/hyperledger/node_modules/grpc/src/client_interceptors.js:705:15
I am using latest version of pre-requisites as mentioned in below link:
http://hyperledger-fabric.readthedocs.io/en/release-1.1/getting_started.html#install-prerequisites
Can anybody tell me where am i going wrong?
Yes, this is due to a new version of grpc released 3 days ago (v1.11.0). The version is controlled by fabric-client and it takes the latest available. You need to delete the grpc module and reinstall it with npm install grpc#1.9.1. This will fix the issue. Going forward you may need to have grpc fixed at 1.9.1 in your package.json until Hyperledger resolve this issue.
Reference:
https://chat.hyperledger.org/channel/general?msg=FME6aDfnfMexWTm6g
I commented these lines in EventHub.js.
It's required only for state log.
For example:
<br/>
<i> var state = -1;<br/>
//if(self._stream) state = self._stream.call.channel_.getConnectivityState();<br/>
logger.debug('on.data - grpc stream state :%s',state);<br/>
</i><br/><br/>
it works fine now.
I'm still getting below error after commenting the line in EventHub.js
Failed to invoke successfully :: TypeError: Cannot read property 'getConnectivityState' of undefined
Previous detailed error:
TypeError: Cannot read property 'getConnectivityState' of undefined
at ClientDuplexStream. (/fabric-samples/fabcar/node_modules/fabric-client/lib/EventHub.js:308:56)
at emitOne (events.js:116:13)
at ClientDuplexStream.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at ClientDuplexStream.Readable.push (_stream_readable.js:208:10)
at Object.onReceiveMessage (/fabric-samples/fabcar/node_modules/grpc/src/client_interceptors.js:1302:19)
at InterceptingListener.recvMessageWithContext (/fabric-samples/fabcar/node_modules/grpc/src/client_interceptors.js:629:19)
at /fabric-samples/fabcar/node_modules/grpc/src/client_interceptors.js:728:14
Faced the same issue while building the web docker
edit package.json
add the line
"dependencies": {
"grpc" : "1.9.1",
build the docker again
issue the docker compose agin ! it works
I was trying to connect the composer bna to IBM blockchain, and I tried out installing grpc 1.9.1.. and even 1.10.1.. I tried out like everything, and the only thing that worked was doing as Kataus suggested, I commented out the lines relate to the getConnectivity state, and it finally connected to the IBM blockchain network I had.
I'm working on a new node.js app on an old server I use for dev stuff.
Both apps have the mongo URL specified:
var mongoUri = 'mongodb://localhost/node';
but on startup, the old node.js app works fine, but the new one doesn't. The new one returns the following for node server.js
Error: unable to connect to database at mongodb://localhost/node
at NativeConnection.<anonymous> (/var/www/server/server.js:15:9)
at emitOne (events.js:115:13)
at NativeConnection.emit (events.js:210:7)
at /var/www/server/node_modules/mongoose/lib/connection.js:336:19
at args.push (/var/www/server/node_modules/mongodb/lib/utils.js:403:25)
at /var/www/server/node_modules/mongodb/lib/mongo_client.js:254:21
at connectCallback (/var/www/server/node_modules/mongodb/lib/mongo_client.js:933:5)
at /var/www/server/node_modules/mongodb/lib/mongo_client.js:782:11
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
Any thoughts or suggestions would be really appreciated. I've tried everything short of reinstalling mongo at this point :(
When I try to start Juggernaut I get this error :
1 Apr 20:21:01 - socket.io ready - accepting connections
node_redis: no callback to send error: ERR unknown command 'subscribe'
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: ERR unknown command 'subscribe'
at RedisReplyParser.<anonymous> (/usr/local/lib/node/.npm/redis/0.5.9/packag
e/index.js:84:27)
at RedisReplyParser.emit (events.js:64:17)
at RedisReplyParser.send_error (/usr/local/lib/node/.npm/redis/0.5.9/package
/lib/parser/javascript.js:251:14)
at RedisReplyParser.execute (/usr/local/lib/node/.npm/redis/0.5.9/package/li
b/parser/javascript.js:110:22)
at RedisClient.on_data (/usr/local/lib/node/.npm/redis/0.5.9/package/index.j
s:328:27)
at Socket.<anonymous> (/usr/local/lib/node/.npm/redis/0.5.9/package/index.js
:99:14)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:672:14)
at IOWatcher.onReadable [as callback] (net.js:177:10)
I didnt find anything to help me!
Try upgrading Redis.
It happened to me, and that's what solved it. I'm using Ubuntu, and the one in the package manager isn't an updated version. It needs to be at least version 2.2.1.
Source: From one of the issues posted on the juggernaut github repo.
EDIT: Upon closer inspection, it looks like you were the one who posted the issue on the github repo. I'll just leave this answer here just in case anyone else has the same problem.