Here is my stack trace when attempting to launch my api side of my react - web app.
I have ran into this error multiple times but never seem to be able to fix it when it comes up again!
/Users/joshua_paulsen/Desktop/Jump-In-Final/api/node_modules/pouchdb-core/lib/index.js:1285
throw new Error('Invalid Adapter: ' + opts.adapter);
^
Error: Invalid Adapter: undefined
at new PouchDB (/Users/joshua_paulsen/Desktop/Jump-In-Final/api/node_modules/pouchdb-core/lib/index.js:1285:11)
at Object.<anonymous> (/Users/joshua_paulsen/Desktop/Jump-In-Final/api/dal.js:18:12)
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 Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/joshua_paulsen/Desktop/Jump-In-Final/api/routes/workouts/index.js:8:5)
I had my db defined like this - const db = new PouchDB(
${process.env.COUCH_HOSTNAME}${process.env.COUCH_DBNAME}
)
the fix ended up being changing it to this.
var pouch = new PouchDB(${process.env.COUCH_DBNAME}, { adapter: "http" })
Related
Im running some code, and when I do npm start I get this error:
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^
TypeError: Router.use() requires a middleware function but got a Object at Function.use (/bustabit-webserver/node_modules/express/lib/router/index.js:458:13)
at Function.<anonymous> (/bustabit- webserver/node_modules/express/lib/application.js:220:21)
at Array.forEach (<anonymous>)
at Function.use (/bustabit- webserver/node_modules/express/lib/application.js:217:7)
at Object.<anonymous> (/bustabit-webserver/server/index.js:93:9)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Line 92 of server/index.js is
app.use('/client_old', express.static(path.join(__dirname, '../client_old'), { maxAge: twoWeeksInSeconds * 1000 }));
I'm just trying to test Hapi.js and, whatever I code, I got this error :
node_modules/hapi/lib/server.js:145
Items.serial(this.connections, (connectionItem, next) => {
^
SyntaxError: missing ) after argument list
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:448:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/gilles/exo1/node_modules/hapi/lib/index.js:5:16)
at Module._compile (module.js:430:26)
at Object.Module._extensions..js (module.js:448:10)
Where does come form this syntax ...() => {... to make a function ?
What I did bad to use Hapi ?
Thank you very much
The syntax is called Arrow function. You use hapi 10 or later which requires node 4+, but you have an older version of node which doesn't support arrow functions yet. The solution is to upgrade your node version to 4 or 5.
I am working through Brad Dayley's Node.js, MongoDB and Angularjs book and I'm stuck on one of his exercises (Listing 4.4). I have a simple script emitterListener.js that is as follows the script is designed to makes checks on an account.
var events = require('events');
function Account() {
this.balance = 0;
events.EventEmitter.call(this);
this.deposit = function(amount) {
this.balance += amount;
this.emit('balanceChanged');
};
this.withdraw = function(amount) {
this.balance -= amount;
this.emit('balanceChanged');
};
}
Account.prototype._proto_ = events.EventEmitter.prototype;
function displayBalance() {
console.log("Account balance: $%d", this.balance);
}
function checkOverdraw() {
if (this.balance < 0) {
console.log("Account Overdrawn!!!!!");
}
}
function checkGoal(acc, goal) {
if (acc.balance > goal) {
console.log("Goal Achieved!!!!!");
}
}
var account = new Account();
account.on("balanceChanged", displayBalance);
account.on("balanceChanged", checkOverdraw);
account.on("balanceChanged", function() {
checkGoal(this, 1000);
});
account.deposit(220);
account.deposit(320);
account.deposit(600);
account.withdraw(1200);
When I run this I get the error.
TypeError: Object #<Account> has no method 'on'
at Object.<anonymous> (/Users/506132/web/emitterListener.js:35:9)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
From my limited understanding after researching I think this means that the "on" module is not being loaded. I found a solution that suggested something similar to adding this to line 1
var events = require('events').on;
which then results in the error.
TypeError: Cannot read property 'EventEmitter' of undefined
at Object.<anonymous> (/Users/506132/web/emitterListener.js:16:35)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Following the logic from the first fix I tried implementing the same fix but with EventEmitter
var events = require('events').EventEmitter;
Hooray it looks like it worked.... or not......and now I get this error
TypeError: Cannot read property 'prototype' of undefined
at Object.<anonymous> (/Users/506132/web/emitterListener.js:17:48)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I tried adding the below code thinking why not?
var events = require('events').prototype;
and it just brings me back to the same error from before
TypeError: Cannot read property 'EventEmitter' of undefined
at Object.<anonymous> (/Users/506132/web/emitterListener.js:16:35)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
What am I doing wrong here? How should I go about debugging this and where should I look? Thanks in advance for helping a newbie out.
Cheers.
process.EventEmitter is deprecated, use require('events') instead.
Search through all your reference files (should be in multiple files) for:
var EventEmitter = process.EventEmitter
An where ever it exists, change that line to this:
var EventEmitter = require('events')
I'll post it as an answer so this question won't get marked as unanswered.
You should change:
Account.prototype.__proto__ = events.EventEmitter.prototype;
to:
Account.prototype = Object.create(events.EventEmitter.prototype);
var EventEmitter = process.EventEmitter
is deprecated in high version of node, use var EventEmitter = require('events') instead
This compilation error because of versions conflicts of npm and node. I had the same issue in my project. I resolved after install the same compatible versions of npm and node as on another machine.
Check:
nmp -v
and
node -v.
All the confusion with the actual example is the first line of code.
var events = require('events');
After Node v6.1.0 this line of code will store EventEmmiter object inside events variable, so there is no need to access it explicitly later.
Solution is very simple, just change
events.EventEmitter.call(this);
to:
events.call(this)
And change
Account.prototype._proto_ = events.EventEmitter.prototype;
to:
Account.prototype._proto_ = events.prototype;
I had the same problem a few minutes ago, I decided to downgrade node to version 6.x, then it worked
I have an issue with exporting a module in Node.js.
Here is a part of my code:
var zmq = require('zmq');
var module = require('module');
var DeviceRequester = function(port, name)
{
...
};
var SMValueGetter = function(socket)
{
...
};
module.exports.DeviceRequester = DeviceRequester;
module.exports.SMValueGetter = SMValueGetter;
When I use it I get the following error:
module.exports.DeviceRequester = DeviceRequester;
^
TypeError: Cannot set property 'DeviceRequester' of undefined
at Object.<anonymous> (<PROJECT_PATH>/node_modules/lse/lib/lse.js:168:32)
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)
at Object.<anonymous> (<PROJECT_PATH>/server.js:6:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
I have no idea why it occurs. I've red the Node.js documentation and some tutorials about exporting modules and all of them do it that way. Am I overlooking something?
Give more attentions at errors
TypeError: Cannot set property 'DeviceRequester' of undefined
at line var module=require("module"); you are overwriting the default module variable.
simple try to change at something that makes more sense, such as
var MyModule=require(..path..)
Strugging to get tower.js installed on my snow leopard macbook. Here is the command and the error:
My-Macbook:tower john$ tower new app
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object #<Object> has no method 'existsSync'
at Object.<anonymous> (/usr/local/lib/node_modules/tower/index.js:6:21)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (/usr/local/lib/node_modules/tower/bin/tower:15:3)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
Beginning with Node.js 0.8, what was path.existsSync() is now fs.existsSync() - the version of tower.js that you're using seems to be incompatible with the installed Node.js version.