AssertionError: path must be a string - node.js

require([
'common',
// Libs
'jquery',
'parse',
'i18n',
// Modules
'modules/login/controllers/login',
'modules/page/controllers/page',
// Styles
'css!../assets/css/bootstrap.min.css',
'css!../assets/css/tablesorter-bootstrap-theme.css',
'css!../assets/css/common.css',
],
function(common, $, Parse, i18n, Login, Page) {
// Defining the application router, you can attach sub routers here.
var Router = Parse.Router.extend({
routes : {
'' : 'index'
},
index : function() {
var currentUser = Parse.User.current(),
view, container;
// Load either login screen or navigation bar,
// depending on the login state of current user.
if(currentUser){
view = new Page.Views.Navbar();
container = '#navbar';
} else {
view = new Login.Views.Login();
container = '#main';
$('#navbar').html(null); // Remove the navbar
}
view.render(function(el) {
$(container).html(el);
});
}
});
$(function() {
// Initialize internationalization
i18n.init({
saveMissing: true,
debug: true,
//preload: ['dk', 'en'],
getAsync: false
});
Parse.initialize('****','****');
// Initialize the Router
var router = new Router();
Parse.history.start({ pushState: false });
});
$(document).on( 'click', 'a:not([data-bypass])', function(evt) {
// Get the anchor href and protcol
var href = $(this).attr('href');
var protocol = this.protocol + '//';
if (href && href.slice(0, protocol.length) !== protocol && href.indexOf('javascript:') !== 0) {
evt.preventDefault();
Parse.history.navigate(href, { trigger: true });
}
});
});
Got error:
assert.js:85
throw new assert.AssertionError({
^
AssertionError: path must be a string
at Module.require (module.js:482:3)
at require (internal/module.js:20:19)
at Object. (/home/historiejagt.portaplay.dk/public_html/app/app.js:4:1)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)

Read the error:
AssertionError: path must be a string
at Module.require (module.js:482:3)
at require (internal/module.js:20:19)
at Object. (/home/historiejagt.portaplay.dk/public_html/app/app.js:4:1)
Look at your code:
require([
An array is not a string.
I think I worked out what's going on, though it would have been a lot easier if someone had been more specific about where they're copy-pasting code from.
The function require(array, callback) is part of RequireJS. NodeJS doesn't use that and has require(string) instead. If you want to use RequireJS in NodeJS you need to install and require requirejs first.

Related

I was writing Discord bot with index.js and .env and I messed with this error while running this in terminal "node index.js"

I want develop my own discord bot here's the contents:
Index code
const { Client } = require("discord.js");
const { config } = require("dotenv");
// Declares our bot,
// the disableEveryone prevents the client to ping #everyone
const client = new Client({
disableEveryone: true
});
config({
path: __dirname + "/.env"
})
// When the bot's online, what's in these brackets will be executed
client.on("ready", () => {
console.log(`Hi, ${client.user.username} is now online!`);
// Set the user presence
client.user.setPresence({
status: "online",
game: {
name: "me getting developed",
type: "WATCHING"
}
});
})
// When a message comes in, what's in these brackets will be executed
client.on("message", async message => {
console.log(`${message.author.username} said: ${message.content}`);
});
// Login the bot
client.login(process.env.TOKEN);
Output
disableEveryone = true
^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
at Module._compile (internal/modules/cjs/loader.js:891:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11
Invalid shorthand property initializer indicates that you used an invalid property initializer. In this case, it looks like you used "=" instead of ":" to declare the property value "true" on property "disableEveryone".
Saving the code as shared and running it again should solve your problem.

Nodejs, Electron nightmare is not defined when it's installed?

I've installed Nightmare via NPM this is my code:
var jquery = require('jquery')
var nightmare = require('nightmare')
var nightmare = Nightmare({ show: true });
$( "#test" ).addEventListener('click',() => {
nightmare
.goto('http://akhiljose.me/master/paste/')
.type('.form-control', 'Test')
.type('input[type=test]', 'nightmare_test')
.click('input[type=submit]')
.wait(7000)
.evaluate(function () {
return document.querySelector('pre').innerText;
})
.end()
.then(function (result) {
console.log(result);
})
.cat(function (error) {
console.error('Search failed:', error);
})});
However console logs:
C:\Users\ninja_000\Desktop\clu-gen\index.js:3 Uncaught ReferenceError: Nightmare is not defined
at Object.<anonymous> (C:\Users\ninja_000\Desktop\clu-gen\index.js:3:17)
at Object.<anonymous> (C:\Users\ninja_000\Desktop\clu-gen\index.js:22:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at file:///C:/Users/ninja_000/Desktop/clu-gen/index.html:12:5
I'm very new to nodejs what is causing this error? Am I do something wrong?
You are calling an undefined variable.
var jquery = require('jquery')
var nightmare = require('nightmare')
var nightmare = Nightmare({ show: true });
The second line declares a variable nightmare but the next line you are calling Nightmare. Make the second line uppercase.
var jquery = require('jquery')
var Nightmare = require('nightmare')
var nightmare = Nightmare({ show: true });
You can see from the second line of the stack trace:
at Object.<anonymous> (C:\Users\ninja_000\Desktop\clu-gen\index.js:3:17)
Line 3:17, there is an uncaught ReferenceError: Nightmare. This make sense because Nightmare is not defined, so nodejs cannot find it. The line numbers in the stack trace are useful to pinpoint where in the code the error is occurring. You can also use a linter which will show an error for trying to use an undefined variable. Something like eslint.
Should've defined as Nightmare not nightmare

I am creating objecting in the classes of a instance at "Syncano' . I am reveiving this ReferenceError: callback is not defined

Here's the error log
ReferenceError: callback is not defined
at Object. (C:\Users\Username\Desktop\JsGame-master\APP.JS:137:45)
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:146:18)
at node.js:404:3
var connection = Syncano({apiKey: 'abc',
userKey: 'abc',
defaults: {
instanceName: "interactiveboard",
className: "players"
}
});
var DataObject = connection.DataObject;
DataObject .please() .list() .then(function(res) {
console.log(res);
});
var dataObject = {
avatar: "Geralt",
nickname: "Rivia",
email:"whatevershit#gmail.com"
};
DataObject.please().create(DataObject).then(callback);
This is happening because the callback you are passing into DataObject.please().create(DataObject).then(callback); is not defined anywhere.
You could solve this in two ways.
One would be to define a callback before you pass it into that call like this:
var callback = function(res) { console.log(res); };
The other would be to change your last line to pass the function directly into the then call like this:
DataObject.please().create(DataObject).then(function(res) {
console.log(res);
});
Hope this helps!

TypeError: Object #<Object> has no method 'Request' with elastic.js

i tried the following sample code:
var es=require("elasticsearch");
var ejs = require("ejs");
var client = new es.Client({
host: 'localhost:9200',
log: 'trace'
});
client.ping({
requestTimeout: 3000,
// undocumented params are appended to the query string
hello: "elasticsearch"
}, function (error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
client.search({
index: 'message-1',
type: 'message',
body: ejs.Request().query(ejs.MatchAllQuery())
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});
i am getting the following error when i try to run: node metric.js
/home/karunakar/test/metricagg/metric.js:27
body: ejs.Request().query(ejs.MatchAllQuery())
^
TypeError: Object #<Object> has no method 'Request'
at Object.<anonymous> (/home/karunakar/test/metricagg/metric.js:27:13)
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:929:3
i could not locate the problem.
-- Thanks
You want the elastic.js module and not ejs, which is a templating engine module.
You can keep the first require("elasticsearch") but the second one should be require("elastic.js") instead of require("ejs")

Replacing karma with jasmine-node for my AngularJS tests?

Jasmine AngularJS test (passes in karma start configs/karma.conf.js)
describe('IndexController', function () {
beforeEach(module('myApp'));
var ctrl, scope;
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
ctrl = $controller('IndexController', {
$scope: scope
});
}));
it('should add name parameter to scope', function () {
expect(scope.name).toBeDefined();
});
});
Contents of controllers.js
var myApp = angular.module('myApp', []);
myApp.controller('IndexController', function ($scope) {
$scope.name = 'bob';
});
Output of: jasmine-node test/ --junitreport
Message:
TypeError: object is not a function
Stacktrace:
TypeError: object is not a function
at null.<anonymous> (/tmp/tests/test/unit/controllerSpec.js:38:16)
at Object.<anonymous> (/tmp/tests/test/unit/controllerSpec.js:36:1)
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)
beforeEach() taks in a function. Be sure module('myApp') and inject(...) are returning actual function definitions. Jasmine's beforeEach is like "call the passed function before each test", so you may want:
beforeEach( function(){ module('myApp') } );
I am unfamiliar with karma, but do use jasmine's done() method in my beforeEach() like this:
var valueForEachTest = null;
beforeEach( function(done) {
doSomething( function(value){
valueForEachTest = value;
done();
});
} );
Not using that done() call breaks my tests because I'm doing a few asynchronous call in there (perhaps Jasmine is not waiting for beforeEach to finish?).
Angular is made to run in the browser. It will not run in node. At least, not without a lot of effort.
There has been an attempt to port it to node, but that project is really intended to render angular pages server side for search engine optimization. Unless you have a really good reason, you shouldn't be trying to test Angular apps in Node.

Resources