proxies not supported on this platform - node.js

i'm trying to make(i don't know what it's called, hot load? hot reload?) Meteor-like real-time loading of data, but by using node.js not Meteor.
and i'm using the ddp module for the client(=browser, i have not tried it yet) and ddp-reactive-server, well, for the server.
server.js is like this:
var DDPServer = require('ddp-server-reactive');
var server = new DDPServer();
var todoList = server.publish('todolist');
after that i run the server using the command node server.js --harmony_proxies(notice i'm already using the flag) this is what i get:
[aseds#localhost ~]$ node server.js --harmony_proxies
/home/aseds/Desktop/projeh/css-goodness/node_modules/harmony-reflect/reflect.js:2049
throw new Error("proxies not supported on this platform. On v8/node/iojs, make sure to pass the --harmony_proxies flag");
^
Error: proxies not supported on this platform. On v8/node/iojs, make sure to pass the --harmony_proxies flag
at global.Proxy (/home/aseds/Desktop/projeh/css-goodness/node_modules/harmony-reflect/reflect.js:2049:13)
at publish (/home/aseds/Desktop/projeh/css-goodness/node_modules/ddp-server-reactive/lib.js:211:32)
at Object.<anonymous> (/home/aseds/Desktop/projeh/css-goodness/ddpserver.js:10:23)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:429:10)
at startup (node.js:139:18)
at node.js:999:3
my nodejs version v5.4.1.
i'm not even sure if that's actually possible to make the automatic reload feature of Meteor this way but i'm trying! :)
Thanks in advance for any help you are able to provide.

I came across this thread with regards to --harmony-proxies:
https://github.com/tvcutsem/harmony-reflect/issues/56
The relevant bit:
I released version 1.4.0 which, when loaded twice according to the script outlined above, loads correctly.
Note that loading v1.3.1 of this library followed by v1.4.0 will still fail (the other way around works fine). So it's important that your dependencies upgrade to the latest version.
It appears that if harmony-proxies is loaded as a node dependency twice, with different versions required, and a version before 1.4.0 is loaded first, then you will see this error.

Related

Socket.io Syntax not Recognized on Server

Node server not able to understand socket.io syntax, even with all packages installed.
When I run my server locally with nodejs server.js it works fine is working. But, when I try to run it on my Ubuntu server, it does not seem to understand this line:
socket.on( 'client-data', ( serverpackage ) => {
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
The directory on my Ubuntu server is user/server, which contains all my server modules. Socket.io is installed, and I even checked to make sure all dependencies for socket.io are there too.
NodeJS-Socket-server-with-DB#1.0.0 /home/<user>/server
└── socket.io#2.1.1
I am also running this version of nodejs:
<user>#host*****:~/server$ nodejs -v
v0.10.25
You can't use arrow functions. You need at minimum version 4 of node however version 6 offers full compatability with arrow functions.
To fix your issue simply update node or change to a regular function like:
socket.on( 'client-data', function (serverpackage) {
Your nodejs version don't understand arrow function, check update if you want use it.
If not, please change arrow function to normal function.
Check Node.js ES2015 Support.

Lambda function failing with Unable to import module 'index'

Error:
Unable to import module 'index': Error
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/node_modules/slack-incoming-webhook/lib/index.js:3:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
By the looks of this my code isn't the problem it's a problem with the slack-incoming-webhook node-module however the piece of offending code is this line which looks completely normal.
var SlackClient = require('./client');
I have tried 4 different packages now (request, http, node-webhooks and now slack-incoming-webhooks) and they are all failing with code in node modules. I am thoroughly confused as I can get the code to work on my own computer and on an Amazon Linux AMI EC2 Instance (running same node version)
All the code is zipped and sent to lambda using the aws-cli and I have deployed node.js code on lambda before without any problems (alexa skill).
I have tried npm install on the ec2 instance, I have tried several different packages and I have come to the conclusion there must be some sort of configuration wrong in lambda but I can't find what. Could someone point me in the right direction...
Here is my code if anyone is curious also the lambda trigger is an aws iot button.
const slack = require('slack-incoming-webhook');
const send = slack({
url: 'https://hooks.slack.com/....'
});
exports.handler = function ()
{
send(process.env.company + ' has pushed their panic button! PANIC! PANIC! PANIC!');
};
This is common issue I have seen in many posts. Most of the cases it is the way zipping the files making the problem. Instead of zipping the folder you have to select all files and zip it like below,
I would simply refer to use Apex (http://apex.run/).
Pretty much awsm serverless framework to be used with AWS Lambda. Once this is setup, no need to do manual zipping.
Simply execute couple of commands:
apex create (to create the lambda)
apex deploy (deploy to your AWS region, no manual zipping required)
apex invoke to invoke it from your terminal.
Thanks

is it possible to set up amdefine in tests so that I don't have to define it in all my module files?

I have a set of objects that are used browser side but tested server side with mocha. I'm using require.js for AMD loading. The Require.js site suggests using amdefine on server-side to get the defined modules to work in node.js with this bit of code:
if (typeof define !== 'function') {
var define = require('amdefine')(module)
}
OK. But I have to put that into every module that I want to use in Node. In my case that means I have to strip it out of any code that I'm using client side (most of it).
I'm wondering if there's any way to put that chunk of code in my test instead so that I don't have to put it in my client side code. It seems silly to have code in my files that will only be needed for the tests -- makes more sense to put it in the test code. However, when I do that I get an error:
Error: amdefine with no module ID cannot be called more than once per file.
at runFactory (/home/vmplanet/dev/alpha/web/node_modules/amdefine/amdefine.js:159:23)
at define (/home/vmplanet/dev/alpha/web/node_modules/amdefine/amdefine.js:275:13)
at Object.<anonymous> (/home/vmplanet/dev/alpha/web/assets/src/coffee/delta/dataLayer.coffee:4:3)
at Object.<anonymous> (/home/vmplanet/dev/alpha/web/assets/src/coffee/delta/dataLayer.coffee:158:4)
at Module._compile (module.js:456:26)
at Object.loadFile (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:179:19)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
It's an odd error, since the amdefine code is only in one place -- the top of the test file. Is there a way to put this amdefine code in my test and only my test and still get the tests to run server side -- without having to strip out the amdefine code for client side?
If you use amd-loader, you can do this:
require("amd-loader");
var datatypes = require("../build/dist/lib/salve/datatypes");
var name_resolver = require("../build/dist/lib/salve/name_resolver");
That's it. You just require amd-loader first and then you can load AMD-style modules at will. (In the example above the two modules loaded after amd-loader are AMD-style modules.) And the AMD-style modules can load other AMD-style modules.
The snippet above is actual code from one of my test suites which tests a library designed AMD-style so that it can be loaded with RequireJS but is tested in Node.js.

NODE_PATH is being ignored or not working

I'm trying to run my node app on a new server and am having some issues with the NODE_PATH environment variable. The app works fine on my local machine (OSX Lion) but not on the server (Redhat linux). When starting my app with node app.js from within my project directory /development/nodeproject, I get the following error :
Error: Cannot find module 'mod/core/models/Category'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at /development/nodeproject/app.js:57:5
at Object.<anonymous> (/development/nodeproject/app.js:258:1)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
mod/core/models/Category is the first require() in my app.js and looks like this: var Category = require('mod/core/models/Category'). So apparently node is not looking for modules in my project directory.
I'm not sure why though, because I made the following changes (that are working just fine on my local machine).
added export NODE_PATH=/development/nodeproject to my ~/.bash_profile
ran source ~/.bash_profile
if I run env I see NODE_PATH=/development/nodeproject listed there
in my app.js if I console log process.env.NODE_PATH I get /development/framework (should this output an array instead of a string?)
Other information that might be relevant:
I'm on node v0.6.7
I'm doing all of this as root (sudo su -)
At this point I'm not sure what else I can do. Any help would be greatly appreciated.
NODE_PATH used for modules, not for solutions files.
Try
module.paths.push("/development/nodeproject", "one/more/path");
before any require() call. And you really should use a relative require like require('./mod/core/models/Category') for files in your nodeproject directory
The functionality you are looking for was removed. Use the node_modules directory or a relative require like require('./mod/core/models/Category').
This answer has more info: NODE_PATH error with node.js while attempting to setup jsctags for vim

Node.js - cannot find module

I'm using Node Boilerplate and it all worked fine until I decided create another project on top of it(in another dir).
Now I have exactly the same code base(this project AS IS) in two different folders. I can run one of it without any problems but another one is failing with:
% node app.js
node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'connect/middleware/router'
at Function._resolveFilename (module.js:299:11)
at Function._load (module.js:245:25)
at require (module.js:327:19)
at Object.<anonymous> (/home/gotts/Sites/nodejs-uploadr/lib/express/lib/express/server.js:17:14)
at Module._compile (module.js:383:26)
at Object..js (module.js:389:10)
at Module.load (module.js:315:31)
at Function._load (module.js:276:12)
at require (module.js:327:19)
at Object.<anonymous> (/home/gotts/Sites/nodejs-uploadr/lib/express/lib/express/index.js:28:31)
There is similar problem explained here - https://github.com/visionmedia/express/issues/535 which says that the problem is in the incompatible version of connect/express.
But how is this possible? Source code is exactly the same in two folders and it work fine in one copy and fails in another?
Do the two folders share a common parent? Node looks for modules in ~/.node_modules and /node_modules in your app dir.
OK, let me answer my own question:
Sorry for misinformation - those two folders were not exactly the same(I'm gonna need to learn unix diff better). And there it require("connect") in code
Local checkout of connect into /lib folder takes precedence but if it's not there - connect will be loaded from the ~/.node_modules as Ricardo previously set.
#see node.js express module not loading properly in the last comment, maybe it helps
the basic idea behind it is to install the module inside your application folder, not on a system level

Resources