Meteor/node-gd & ReferenceError: require is not defined - javascript

I have a few related questions about node-gd and Meteor.
First couple of questions. I've tried to install node-gd in what I believe is the correct place.
Does this look like I've installed it to the correct location for use with Meteor?
Should I be worried about the warnings in the output?
me#ubuntu:/usr/local/lib$ sudo npm install node-gd
npm http GET https://registry.npmjs.org/node-gd
npm http 304 https://registry.npmjs.org/node-gd
> node-gd#0.2.3 install /usr/local/lib/node_modules/node-gd
> node-gyp rebuild
make: Entering directory `/usr/local/lib/node_modules/node-gd/build'
CXX(target) Release/obj.target/node_gd/cpp/node-gd.o
../cpp/node-gd.cpp: In static member function ‘static v8::Handle<v8::Value> Gd::Image::StringFTBBox(const v8::Arguments&)’:
../cpp/node-gd.cpp:1045:22: warning: variable ‘color’ set but not used [-Wunused-but-set-variable]
REQ_INT_ARG(0, color);
^
../cpp/node-gd.cpp:41:7: note: in definition of macro ‘REQ_INT_ARG’
int VAR; \
^
SOLINK_MODULE(target) Release/obj.target/node_gd.node
SOLINK_MODULE(target) Release/obj.target/node_gd.node: Finished
COPY Release/node_gd.node
make: Leaving directory `/usr/local/lib/node_modules/node-gd/build'
node-gd#0.2.3 node_modules/node-gd
me#ubuntu:/usr/local/lib$ ls
node_modules python2.7 python3.4
me#ubuntu:/usr/local/lib$ cd node_modules/
me#ubuntu:/usr/local/lib/node_modules$ ls
meteorite node-gd
I am passing coordinates back to the server and I want to use node-gd to manipulate an image on the server.
This is my Meteor method:
Meteor.methods({
createImage: function(coords) {
console.log('createImage')
console.log(coords.x);
var gd = require('gd');
}
});
When I try to run this function I get this on my terminal:
I20140826-06:44:18.166(-7)? Exception while invoking method 'createImage' ReferenceError: require is not defined
I20140826-06:44:18.166(-7)? at Meteor.methods.createImage (app/server/server.js:7:15)
I20140826-06:44:18.167(-7)? at maybeAuditArgumentChecks (packages/livedata/livedata_server.js:1487)
I20140826-06:44:18.167(-7)? at packages/livedata/livedata_server.js:643
I20140826-06:44:18.168(-7)? at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20140826-06:44:18.168(-7)? at packages/livedata/livedata_server.js:642
I20140826-06:44:18.168(-7)? at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20140826-06:44:18.168(-7)? at _.extend.protocol_handlers.method (packages/livedata/livedata_server.js:641)
I20140826-06:44:18.168(-7)? at packages/livedata/livedata_server.js:541
The answer to this question suggests various JS solutions. Is this what I need, can anyone recommend what's best to use for Meteor for both server and client?

You can't add NPM modules to meteor this way, you should use the npm atmosphere package from meteorhacks : http://atmospherejs.com/package/npm
What you need to do is install the package via meteorite :
mrt add npm
Then add a packages.json in your project root and specify the node-gd dependency :
{
"node-gd":"0.2.3"
}
Finally, in your server code use Meteor.require to access the node-gd API.
Be aware though that Meteor server side programming uses Fibers so you'll have to wrap async API calls to node-gd using either Meteor._wrapAsync or the set of Async utilities that come with the npm atmosphere package.
Here is a nice article on understanding this point : https://www.discovermeteor.com/blog/understanding-sync-async-javascript-node/
You can't use NPM packages on the client.

Try using Meteor.npmRequire('your module name')

Related

Streamr node install on putty (issues)

The guide I am using https://www.youtube.com/watch?v=9cdsQWRDNM4 time marker (7:27) is where it goes to all wrong.
This is where I am having issue with my Streamr node install. Its a very basic install. The issue I am having is I'm very new to putty and this section isn't the same as the install is supose to be -- /root/.streamr/config/default.json but when I change it it becomes another error. The following sentence is what I am generating which becomes an error also which prevents myself from starting my node up (on my vps) Select a path to store the generated config in /home/streamr/.streamr/config/default.json
Either way I am getting an error.
**This is a screen shot of what I am dealing with !!! Any help with putty and setting up VPS would be great. **
can provide actual screenshot if needed!!
: Welcome to the Streamr Network
: Your node's generated name is Leopard Wrist Pond.
: View your node in the Network Explorer:
:
: You can start the broker now with
: streamr-broker /home/streamr/.streamr/config/default.json
root#ubuntu-s-1vcpu-1gb-tor1-01:~# docker run -it -p 7170:7170 -p 7171:7171 -p 1883:1883 -v $(cd ~/.streamr Docker; pwd):/root/.streamr streamr/broker-node:latest streamr/broker-node:lates **Error: Config file not found in the default location. You can run "streamr-broker-init" to generate a confi g file interactively, or specify the config file as argument: "streamr-broker path-to-config/file.json"
at readConfigAndMigrateIfNeeded (/home/streamr/network/packages/broker/dist/src/config/migration.js:155 ** :19)
at Command. (/home/streamr/network/packages/broker/dist/bin/broker.js:20:69)
at Command.listener [as _actionHandler] (/home/streamr/network/node_modules/commander/lib/command.js:48 8:17)
at /home/streamr/network/node_modules/commander/lib/command.js:1227:65
at Command._chainOrCall (/home/streamr/network/node_modules/commander/lib/command.js:1144:12)
at Command._parseCommand (/home/streamr/network/node_modules/commander/lib/command.js:1227:27)
at Command.parse (/home/streamr/network/node_modules/commander/lib/command.js:897:10)
at Object. (/home/streamr/network/packages/broker/dist/bin/broker.js:41:6)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
npm notice
npm notice New major version of npm available! 8.19.3 -> 9.4.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.4.2
npm notice Run npm install -g npm#9.4.2 to update!
npm notice
Ive tried both ways for the file name but both end in errors. Im nt sure why its not generating a /root/.streamr/config/default.json. Its giving me this strange file name that doesn't work either streamr-broker /home/streamr/.streamr/config/default.json. This one will let me finish the set up of the docker but it will not let me start the node and generates an error as seen in the code!

"gatsby develop" cannot run in Mac M1

Iam using gatsby 3.1.2 version with strapi as CMS, were i could not able to run gatsby develop and it is throwing this below mentioned error. Also attached the screenshot from terminal.
ERROR
Invalid options object. Ignore Plugin has been initialized using an options object that does not match the API schema.
- options should be one of these:
object { resourceRegExp, contextRegExp? } | object { checkResource }
Details:
* options misses the property 'resourceRegExp'. Should be:
RegExp
-> A RegExp to test the request against.
* options misses the property 'checkResource'. Should be:
function
-> A filter function for resource and context.
System Informations:
Gatsby CLI version: 4.0.0
Gatsby version: 3.14.6
Node version: v14.18.0
NPM version: 6.14.15
In case it helps anyone, prior to this error (where it just doesn't run, without throwing any errors or clues) I had a hard time with npm install, but I was able to fix that by running the following:
brew reinstall vips
xcode-select --install
brew install gcc
brew reinstall vips
brew info vips
npm i

Error pty.js install?

I have run into an unusal problem when trying to install pty.js using node:
If I run npm install pty.js I receive this error:
> pty.js#0.3.1 install
/Users/username/WebstormProjects/example/node_modules/pty.js
> node-gyp rebuild
CXX(target) Release/obj.target/pty/src/unix/pty.o
In file included from ../src/unix/pty.cc:20:
In file included from ../node_modules/nan/nan.h:190:
../node_modules/nan/nan_maybe_43_inl.h:88:15: error: no member named 'ForceSet' in 'v8::Object'
return obj->ForceSet(GetCurrentContext(), key, value, attribs);
~~~ ^
In file included from ../src/unix/pty.cc:20:
../node_modules/nan/nan.h:816:18: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
return node::MakeCallback()
^
I read post "Errors installing pty.js (node) on OS X" but he did not help me to solve the problem.
you need remove sumbol ^ in you package.json
"ajv": "6.0.0",
"ajv-keywords": "3.2.0"
this error in nodejs ^10
(nuxt.js project)
The package is not maintained anymore, so it does not support last node (more info)
Use node#8 or migrate to node-pty (at the time of writing, node#12 is supported only by node-pty#beta)

Error message from "jspm install jquery"

I am working through the tutorial on the jspm.io site
https://github.com/jspm/jspm-cli/wiki/Getting-Started
All works fine until I get to item 3, where I try to execute
jspm install jquery
and I get this error message
warn Error on getOverride for jspm:github, retrying (2).
ReferenceError: ui is not defined
at c:\Projects\Project1\node_modules\jspm\node_modules\jspm-registry\registry.js:157:5
nodejs is v0.12.0
npm is 2.5.1
jspm is 0.14.0
and this is on Windows 8.1
Does anyone have any clue what is causing this?
This looks like it was because there was an error while jspm was trying to create the local registry clone. Ensure you have git installed as git on your machine. Otherwise it may be a permissions issue.
This was a logging bug though - have fixed it with an update to the registry, so that the error should be slightly more useful next time if you update jspm.
I was getting a similar error with jspm but my problem was actually in how nodejs child_process.exec was calling the git command.
child_process.exec was running
C:\Windows\system32\cmd.exe /s /c "git clone --depth=1 github.com/jspm/registry.git .
However cmd.exe was still auto running commands set in the registry first. In my case the command changing the working folder. So the cwd was being overridden.
Check your registry settings for:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
If there is a command in there to set the drive of working folder it will cause the above error.
Also
With your working folder as c:\, try ruuning the following nodejs code:
var exec = require('child_process').exec;
exec('dir', { cwd: 'C:/windows/fonts' }, function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
});
If it does not list the contents of the fonts folder then your problem is more likely with child_process.exec in node

Failed to load c++ bson extension

A total node noob here. I've been trying to set up a sample node app but the following error keeps popping up every time I try to run:
node app
Failed to load c++ bson extension, using pure JS version
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [#$%67890 :27017]
at null.<anonymous> (/home/thejazeto/code/nodejs/authen/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:553:74)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (/home/thejazeto/code/nodejs/authen/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/home/thejazeto/code/nodejs/authen/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:830:16
at process._tickCallback (node.js:415:13)
I guess you did not have the make tools available when you installed your mongodb library. I suggest you do
xcode-select --install (on a mac)
or sudo apt-get install gcc make build-essential (on ubuntu)
and run
rm -rf node_modules
npm cache clean
npm install
OR just npm update based on #tobias comment (after installing build-essential)
npm update
I just resolved that.
When you install the mongoose module by npm, it does not have a built bson module in it's folder. In the file node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js, change the line
bson = require('../build/Release/bson');
to
bson = require('bson');
and then install the bson module using npm.
I have sorted the issue of getting the "Failed to load c++ bson extension" on raspbian(debian for raspberry) by:
npm install -g node-gyp
and then
npm update
I was unable to solve this
until now. First of all you have to have system packages mentioned by Pradeep Mahdevu. Those are:
xcode-select --install (on a mac)
or
sudo apt-get install gcc make build-essential (on ubuntu)
Then I've installed node-gyp
npm install -g node-gyp
like datadracer said but npm update also suggested by him is risky. It update all modules, which can be dangerous (sometimes API changes between versions).
I suggest going into node_modules/mongodb/node_modules/bson directory and from there use
node-gyp rebuild
That solved the problem for me.
A common problem is that node-gyp requires Python 2.x and if your system's python points to 3.x, it will fail to compile bson, without warning. You can fix this by setting a python global key in your npm config that points to the 2.x executable on your system. For example, on Arch Linux:
npm config -g set python "/usr/bin/python2"
On WIN 8.1
It seems I used a wrong version of mongoose in my package.json file.
I removed the line "mongoose" : "^3.8.15" from package.json.
CLI:
npm install mongoose --save
Now it says "mongoose": "^4.0.6" in package.json and the error I had is gone.
I'm running Ubuntu 14.04 and to fix it for me I had to create a symlink for node to point to nodejs as described here:
nodejs vs node on ubuntu 12.04
Once I did that I re-ran these commands:
rm -rf node_modules
npm cache clean
npm install
So in my case, I first tried to check under this directory /node_modules/mongoose/node_modules/, just to confirm that I have the bson module.
I figured out that I did not have it in the first place, then I just run
npm install bson
and then
npm update
All got sorted.Tried and tested in Ubuntu.
just wanted to say I also had the error
Failed to load c++ bson extension, using pure JS version
But with none of the other errors. I tried everything and turns out the mongodb drivers that I was specifying in the package.json file was incompatible with my version of MongoDB. I changed it to my latest version which was (1.4.34) and it worked!!!
sudo npm rebuild was what fixed it for me.
I finally corrected this error by updating my mongodb dependency version to ~2.0.36 in package.json.
"dependencies": {
"consolidate": "~0.9.1",
"express": "3.x",
"mongodb": "~2.0.36",
"mongoose": "^4.1.12"
}
Unfortunately, All the above answers are only half right..
Took a long time to figure this out..
Mongoose bson install via npm throws warning and causes the error...
npm install -g node-gyp
git clone https://github.com/mongodb/js-bson.git
cd js-bson
npm install
node-gyp rebuild
This works like magic!!
For me it only take to run these commands in my api directory:
rm -rf node_modules
npm cache clean
npm install
I just ran:
sudo npm install bson
and
sudo npm update
and all become ok.
The bson extension message is just a warning, I get it all the time in my nodejs application.
Things to check:
MongoDB instance: Do you have a MongoDB instance running?
Config: Did you correctly configure Mongoose to your MongoDB instance? I suspect your config is wrong, because the error message spits out a very weird string for your mongodb server host name..
I fixed this problem on CentOS by
sudo yum groupinstall "Development Tools"
sudo npm install -g node-gyp
rm -r node_modules
npm cache clean
npm install
I fixed it by changing line 10 of:
/node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js
from:
bson = require('../build/Release/bson');
to:
bson = require('bson');
I also got this problem and it caused my sessions not to work. But not to break either...
I used a mongoose connection.
I had this:
var mongoose = require('mongoose');
var express = require('express');
var cookieParser = require('cookie-parser');
var expressSession = require('express-session');
var MongoStore = require('connect-mongo')(expressSession);
...
var app = express();
app.set('port', process.env.PORT || 8080);
app.use(bodyParser);
mongoose.connect('mongodb://localhost/TEST');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
console.log('MongoDB connected');
});
app.use(cookieParser());
app.use(expressSession({
secret: 'mysecret',
cookie: {
maxAge: null,
expires: moment().utc().add('days',10).toDate(),// 10 dagen
},
store: new MongoStore({
db: 'TEST',
collection: 'sessions',
}),
Very straightforward. But req.session stayed always empty.
rm -rf node_modules
npm cache clean
npm install
Did the trick. Watch out you dont have a 'mongodb' in your package.json! Just Mongoose and connect-mongo.
Here's how I fixed the problem on Ubuntu:
ln -s /usr/bin/nodejs /usr/bin/node
npm install node-gyp
cd node_modules/mongodb/node_modules/bson
node-gyp rebuild
Inspired by #mbochynski answer, but I had to create a symbolic link first, otherwise the rebuild failed.
i was having same trouble tried so many options but in the last npm intall in my mean app folder worked.
I had this problem because I was including the node_modules folder in my Git repository. When I rebuilt the node_modules on the other system it worked. One of them was running Linux, the other OS X. Maybe they had different processor architectures as well.
I had the same problem on my EC2 instance. I think the initial cause was because I had a Node instance running when I installed Mongo. I stopped the Node service and then ran
sudo npm update
inside of the top level folder of my node project. This fixed the problem and everything was just like new
I was trying to run node on virtual machine (vagrant) shared folder. That was a problem. My host machine is Windows, installed node on Windows and worked like a charm. So if you are using virtual machine, just try to run node server on host machine.
I just had the same problem and literally nothing worked for me. The error was showing kerberos is causing the problem and it was one of the mongoose dependencies. Since I'm on Ubuntu, I thought there might be permission issues somewhere between the globally installed packages -- in /usr/lib/node_modules via sudo, and those which are on the user space.
I installed mongoose globally -- with sudo of course, and everything began working as expected.
P.S. The kerberos package now also is installed globally next to mongoose, however I can't remember if I did it deliberately -- while I was trying to solve the problem, or if it was there from the beginning.
I'm working on Docker with centOS 7, and encountered the same problem.
after looking around, and make several tries, I fixed this problem by installing mongodb, and mongodb-server
yum install mongodb mongodb-server
I don't think this is the best way to produce the minimal container. but I can limit the scope into the following packages
==============================================================================================================
Package Arch Version Repository Size
==============================================================================================================
Installing:
mongodb x86_64 2.6.5-2.el7 epel 57 M
mongodb-server x86_64 2.6.5-2.el7 epel 8.7 M
Installing for dependencies:
boost-filesystem x86_64 1.53.0-18.el7 base 66 k
boost-program-options x86_64 1.53.0-18.el7 base 154 k
boost-system x86_64 1.53.0-18.el7 base 38 k
boost-thread x86_64 1.53.0-18.el7 base 56 k
gperftools-libs x86_64 2.1-1.el7 epel 267 k
libpcap x86_64 14:1.5.3-3.el7_0.1 updates 137 k
libunwind x86_64 1.1-3.el7 epel 61 k
snappy x86_64 1.1.0-3.el7 base 40 k
For Windows 7.1, these directions helped me to fix my build environment:
https://github.com/mongodb/js-bson/issues/58#issuecomment-68217275
http://christiankvalheim.com/post/diagnose_installation_problems/
I was able to resolve by uninstalling and reinstalling monk package.
Initial install seemingly had a corrupt mongodb/bson dependency.
Followint #user1548357 I decided to change the module file itself. So as to avoid the problems pointed out by the valid comments below I included my changes in a postinstall script so that I can set it and forget it and be assured that it will run when my modules are installed.
// package.json
"scripts": {
// other scripts
"postinstall": "node ./bson.fix.js"
},
and the script is:
// bson.fix.js
var fs = require('fs');
var file = './node_modules/bson/ext/index.js'
fs.readFile(file, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = data.replace(/\.\.\/build\/Release\/bson/g, 'bson');
fs.writeFile(file, result, 'utf8', function (err) {
if (err) return console.log(err);
console.log('Fixed bson module so as to use JS version');
});
});
easily kick out the problem by just add this line both try and catch block
path: node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js
bson = require('bson'); instead
bson = require('./win32/ia32/bson');
bson = require('../build/Release/bson');
That is all!!!
The only thing which helps me on Windows 7 (x64): https://stackoverflow.com/a/29714359/2670121
Reinstall node and python with x32 versions.
I spent a lot of time with this error:
Failed to load c++ bson extension
and finally, when I installed module node-gyp (for building native addons) and even installed windows SDK with visual studio - nodejs didn't recognize assembled module bson.node as a module. After reinstalling the problem is gone.
Again, What does this error mean?
Actually, it's even not error. You still can use mongoose. But in this case, instead of fast native realization of bson module, you got js-realization, which is slower.
I saw many tips like: "edit path deep inside node_modules..." - which is totally useless, because it does not solve the problem, but just turned off the error messages.

Categories