ReferenceError: self is not defined - node.js

When i try to run my javascript (firebase.js taken from https://firebase.google.com/docs/web/setup) in nodejs i have the error ReferenceError: self is not defined :
C:\Program Files\nodejs>node.exe c:\Temp\firebase.js
c:\Temp\firebase.js:535
I.prototype.onTokenRefresh=function(){throw this.a.create("only-available-in-window");};I.prototype.onTokenRefresh=I.prototype.onTokenRefresh;I.prototype.setBac
kgroundMessageHandler=function(){throw this.a.create("only-available-in-sw");};I.prototype.setBackgroundMessageHandler=I.prototype.setBackgroundMessageHandler;I
.prototype.delete=function(){D(this.c)};var J=function(a,b){var c={};return c["firebase-messaging-msg-type"]=a,c["firebase-messaging-msg-data"]=b,c};var K=self,
P=function(a){I.call(this,a);var b=this;this.a=new firebase.INTERNAL.ErrorFactory("messaging","Messaging",x);K.addEventListener("push",function(a){return L(b,a)
},!1);K.addEventListener("pushsubscriptionchange",function(a){return N(b,a)},!1);K.addEventListener("notificationclick",function(a){return O(b,a)},!1);this.b=nu
ll};f(P,I);
ReferenceError: self is not defined
at Object.<anonymous> (c:\Temp\firebase.js:535:476)
at Object.<anonymous> (c:\Temp\firebase.js:547:800)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
any ideas what i can do to avoid it ?

K is being set to the value of 'self' (var K=self), but 'self' has not been defined yet. If you copied this code from another source, make sure you got all of it. From the looks of it, I think you would be ok changing 'self' to 'this'.

Related

yo #microsoft/sharepoint will retrun this error "TypeError: lookups.flatMap is not a function"

I have node.js version
C:\helloworld-webpart>node -v
v10.24.1
and when i run this command using cmd windows i got this error:-
C:\helloworld-webpart>yo #microsoft/sharepoint
C:\Users\mohan\AppData\Roaming\npm\node_modules\yo\node_modules\yeoman-environment\lib\resolver.js:70
filePatterns: lookups.flatMap(prefix => [`${prefix}/*/index.ts`, `${prefix}/*/index.js`, `${prefix}/*/index.cjs`, `${prefix}/*/index.mjs`]),
^
TypeError: lookups.flatMap is not a function
at Environment.resolver.lookup (C:\Users\mohan\AppData\Roaming\npm\node_modules\yo\node_modules\yeoman-environment\lib\resolver.js:70:27)
at init (C:\Users\mohan\AppData\Roaming\npm\node_modules\yo\lib\cli.js:130:7)
at pre (C:\Users\mohan\AppData\Roaming\npm\node_modules\yo\lib\cli.js:89:3)
at Object.<anonymous> (C:\Users\mohan\AppData\Roaming\npm\node_modules\yo\lib\cli.js:219:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
any advice?

"handlebars.registerHelper is not a function"

I want to create a simple reverse handlebars helper, but on app.js running, I have this error:
TypeError: exphbs.registerHelper is not a function
at Object.<anonymous> (C:\wamp64\www\test\login\server\example.js:7:8)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)
Thank you very much
Nathan
Assuming the following:
const exphbs = require('exphbs');
To manually register a helper, use this:
const handlebars = exphbs.handlebars;
handlebars.registerHelper('hello', function() {
return new handlebars.SafeString('Hello!');
});
Taken from the fine manual.

global declared variable is not visible in other module

I'm declaring global variable as follows:
var NODE_MODULES_PATH = process.env.NODE_PATH || 'C:/Users/../AppData/Roaming/npm/node_modules/';
global.NODE_PATH = NODE_MODULES_PATH;
but when I'm accessing it in other module e.g. flollows:
var mysql = require(NODE_PATH + 'mysql');
it gives following error:
ReferenceError: NODE_PATH is not defined
at Object.<anonymous> (z:\$app4pc\website_engine\conf\dbconnection.js:1:83)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (z:\$app4pc\website_engine\models\login_model.js:1:76)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
Process finished with exit code 1
Node.js does not automatically put things in the global scope. You should export it from your module and require it in the one that uses it. If you must set a global variable, you can use:
var GLOBAL.NODE_MODULES_PATH = ...

Node App - ReferenceError: uriUtil is not defined

I was workign on a Node App a few weeks ago which worked fine. I went to restart it today and its throwing this error
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
^
ReferenceError: uriUtil is not defined
at Object.<anonymous> (d:\A\B\C\Web Applications\Donations1\routes\donations.js:14:19)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (d:\A\B\C\Web Applications\Donations1\app.js:9:17)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:139:18)
at node.js:999:3
It relates to this line of code that connects to mongodb
var mongodbUri = 'mongodb://AAA:BBB#ds053305.mongolab.com:12345/donations';
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
You can replace this line:
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
Which this line:
var mongooseUri =require('mongodb-uri').formatMongoose(mongodbUri);
Don't worry to require same module more than once. Node always require only one time, and after that use the cache for loading the module.

Getting type error with Sequelizejs

Im getting the following error and I can't figure out through the stack trace where it's erroring.
/Users/rahulsharma/Desktop/Jobletics/node_modules/sequelize/lib/sequelize.js:298
this.importCache[path] = defineCall(this, DataTypes)
^
TypeError: object is not a function
at module.exports.Sequelize.import (/Users/ra/Desktop/Js/node_modules/sequelize/lib/sequelize.js:298:32)
at db.sequelize (/Users/ra/Desktop/Js/models/index.js:14:33)
at Array.forEach (native)
at Object.<anonymous> (/Users/ra/Desktop/Js/models/index.js:13:4)
at Module._compile (module.js:456:26)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
Here is the git:
https://github.com/rahul1346/jb
Any idea?
business_model.js is an empty file.

Resources