Error: Cannot find module 'camelcase' - node.js

I'm trying to run a gulp based application.
On Ubuntu, everything is working, but on Debian server not.
Ubuntu: npm: 5.3.0, nodejs: v8.2.1, bower#1.8.0, gulp-cli#1.4.0, npm#5.3.0
Debian: npm: 5.3.0, nodejs: v8.2.1, bower#1.8.0, gulp-cli#1.4.0, npm#5.3.0
Gulpfile:
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
gulp.task('scss2css', function () {
gulp.src(['./web/scss/style.scss'])
.pipe(sass({outputStyle: 'compressed'}))
.pipe(gulp.dest('./web/css/'));
});
gulp.task('scss2css:watch', function () {
gulp.watch('./scss/**/*.scss', ['scss2css']);
});
gulp.task('default', function () {
gulp.start('scss2css');
});
When I type "gulp", I receive message like below:
module.js:487
throw err;
^
Error: Cannot find module 'camelcase'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/gulp-cli/node_modules/yargs/lib/parser.js:3:17)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)

I just removed nodejs package and directories:
/usr/lib/node_modules/
/usr/local/lib/node_modules/

Related

mocha test problem in Ubuntu:ReferenceError: ert is not defined

I am using mocha to test my node js code. While running on windows machine, I am able to test my application successfully. But when I am trying to test same application project in Ubuntu , I am getting ReferenceError: ert is not defined . So i did "rm -rf node_modes" and "npm i" again . But the issue still persist.
Error in terminal
$ npm test
> myapplication#1.0.0 test /NodeProject/MyApplication
> mocha Test/* --require #babel/register
/NodeProject/MyApplication/node_modules/yargs/yargs.js:1163
else throw err
^
ReferenceError: ert is not defined
at Object.<anonymous> (/NodeProject/MyApplication/Test/app.test.js:1:4)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Module._compile (/NodeProject/MyApplication/node_modules/pirates/lib/in dex.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Object.newLoader [as .js] (/NodeProject/MyApplication/node_modules/pira tes/lib/index.js:104:7)
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 Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at /NodeProject/MyApplication/node_modules/mocha/lib/mocha.js:330:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/NodeProject/MyApplication/node_modules/mocha/lib/moch a.js:327:14)
at Mocha.run (/NodeProject/MyApplication/node_modules/mocha/lib/mocha.js:8 04:10)
at Object.exports.singleRun (/NodeProject/MyApplication/node_modules/mocha /lib/cli/run-helpers.js:207:16)
at exports.runMocha (/NodeProject/MyApplication/node_modules/mocha/lib/cli /run-helpers.js:300:13)
at Object.exports.handler.argv [as handler] (/NodeProject/MyApplication/no de_modules/mocha/lib/cli/run.js:296:3)
at Object.runCommand (/NodeProject/MyApplication/node_modules/yargs/lib/co mmand.js:242:26)
at Object.parseArgs [as _parseArgs] (/NodeProject/MyApplication/node_modul es/yargs/yargs.js:1087:28)
at Object.parse (/NodeProject/MyApplication/node_modules/yargs/yargs.js:56 6:25)
at Object.exports.main (/NodeProject/MyApplication/node_modules/mocha/lib/ cli/cli.js:63:6)
at Object.<anonymous> (/NodeProject/MyApplication/node_modules/mocha/bin/_ mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787: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:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! Test failed. See above for more details.
And here is my app.test.js file
var assert = require('assert')
, expect = require('expect.js'),
W3CWebSocket = require('websocket').w3cwebsocket;
describe('Test Suite', function() {
var client;
beforeEach(function(done) {
client = new W3CWebSocket('ws://localhost:8091/', 'echo-protocol');
client.onopen = function() {
console.log('WebSocket Client Connected');
done();
};
client.onclose = function() {
console.log('echo-protocol Client Closed');
};
});
afterEach(function(done) {
if(client!=null){
client.close();
}
done();
});
it('My App result', (done) => {
if (client.readyState === client.OPEN) {
client.send(`"data":"dummy"}`);
}
client.onmessage = function(e) {
let data = e.data;
expect(data).to.not.equal(null);
expect(data).to.not.equal(undefined);
done();
};
});
});
I faced similar issue. It was because babel version in package.json is different from the one whose specific settings are set in .babelrc file
Try deleting .babelrc file and see if it works.
The ert probably is from
.../node_modules/babel-core/lib/transformation/file/options/option-manager.js:128
log.error or log.ert
If not search whole directory for ert, that should give you some clue

mongoose.connect not invoking callback after connection to mongodb

I'm trying to make a connection to MongoDB using Mongoose. But it does neither throw a error nor connect to the database. Following is my code.
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
const mongoose = require('mongoose');
console.log('Hi, there!!');
mongoose.connect('mongodb://localhost:27017/db_name', (err) => {
console.log('Callback called');
if(err) throw err;
console.log('Connected to database');
})
In the above code none of the console.log inside the callback do happen. But any place outside the mongoose.connect do work like console.log('Hi, there!!')
Versions Used
express: 4.0.0
mongoose: 3.8.40
node: 7.7.3
mongodb: 3.4.0
Using mongoose: 3.8.40 I got this in the console :
{ Error: Cannot find module '../build/Release/bson'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/kevin/nemeacreation/sites/test/stackoverflow/node_modules/bson/ext/index.js:15:10)
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) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
Hi, there!!
upgrading to "mongoose": "~4.4" fixed it for me. I got the answer here : https://stackoverflow.com/a/35516644/2829540
For info the latest release of mongoose is 4.10.4

karma start throwing useragent error

I generated an app using yeoman by doing this in a folder called sw-front:
yo angular
I installed karma like this
npm install -g karma
npm install -g karma-cli
grunt serve works fine.
karma -v throws the same error:
mm-mac-2186:sw-front pkatepalli$ karma start
module.js:340
throw err;
^
Error: Cannot find module 'useragent'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/pkatepalli/Desktop/hands-on-angular/sw-front/node_modules/karma/lib/helper.js:4:17)
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)
module.js:
var Module = function() {
var providers = [];
this.factory = function(name, factory) {
providers.push([name, 'factory', factory]);
return this;
};
this.value = function(name, value) {
providers.push([name, 'value', value]);
return this;
};
this.type = function(name, type) {
providers.push([name, 'type', type]);
return this;
};
this.forEach = function(iterator) {
providers.forEach(iterator);
};
};
module.exports = Module;
mm-mac-2186:sw-front pkatepalli$ node -v
v0.10.28
mm-mac-2186:sw-front pkatepalli$ npm -v
1.4.9
Try
npm cache clean
And removing the node_modules directory, if it exists, where you are running the commands form.
Then rebuild/reinstall

Error: Cannot find module 'zeparser'

I have node.js successfully installed. I have created the file
var http = require('http');
var url=require('url');
var fs=require('fs');
var io = require('socket.io');
http.createServer(function (req, res) {
fs.readFile('/var/www/nodeJS/client.html' ,
function ( err, data ) {
if ( err ) {
console.log( err );
res.writeHead(500);
return res.end( 'Error loading client.html' );
}
res.writeHead( 200 );
res.end( data );
});
}).listen(8124, '127.0.0.1');
io.listen(http);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
The error occurs whenever I use the io object. Without io it works fine.
Error: Cannot find module 'zeparser'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/nodeJS/node_modules/socket.io/node_modules/socket.io-client/node_modules/active-x-obfuscator/index.js:1:78)
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)
After this I have also separately installed module zeparser. My default npm installation directory seems to be /usr/local/lib/node_modules.
I have set NODE_PATH as
export NODE_PATH="/usr/local/lib/node_modules"
but get the same error.
Then I tried to copy zeparser module to /var/www/nodeJS/node_modules. Then the error changes to
/var/www/nodeJS/node_modules/socket.io/lib/manager.js:104
server.on('error', function(err) {
^
TypeError: Object #<Object> has no method 'on'
at new Manager (/var/www/nodeJS/node_modules/socket.io/lib/manager.js:104:10)
at Object.exports.listen (/var/www/nodeJS/node_modules/socket.io/lib/socket.io.js:78:10)
at Object.<anonymous> (/var/www/nodeJS/app.js:35: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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:903:3
On your root project, do:
$ sudo npm install zeparser
It resolved the problem for me.

runnuning echo server on Ubuntu

I followed this tutorial to install the node.js on ubuntu and installation is successful. But when i type node echo-server.js i am getting following error:
module.js:340
throw err;
^
Error: Cannot find module '../../lib/ws/server'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/jci/node/joyent-node-283d735/echo-server.js:2:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:487:10)
echo server code:
var sys = require("util")
, ws = require('../../lib/ws/server');
var server = ws.createServer({debug: true});
// Handle WebSocket Requests
server.addListener("connection", function(conn){
conn.send("Connection: "+conn.id);
conn.addListener("message", function(message){
conn.send("<"+conn.id+"> "+message);
if(message == "error"){
conn.emit("error", "test");
}
});
});
server.addListener("error", function(){
console.log(Array.prototype.join.call(arguments, ", "));
});
server.addListener("disconnected", function(conn){
server.broadcast("<"+conn.id+"> disconnected");
});
server.listen(8000);
But lib/ws/server is missing. But where do i get it from??
I don't have web socket server in my node.js installation i guess.
Thanks
Sneha

Resources