node is crashing at the following line:
var tcp = require('tcp'),
error text:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'tcp'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object.<anonymous> (C:\Program Files\nodejs\websocket\websocket.js:11:11)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Module.require (module.js:357:17)
What is the problem? I found the source on the Internet, and the author, and the visitors also can run it...
Try require('net') instead:
$ node
> var tcp = require('tcp');
The 'tcp' module is now called 'net'. Otherwise it should have a similar interface.
> var tcp = require('net');
> $
Others are able to run, may be because they are using Node module when 'tcp' was there...
Now its called 'net', but its all the same thing no need of checking..
If you want to cross check for your more information, here are the links:
1.http://nodejs.org/api/net.html
2.https://github.com/joyent/node/blob/master/lib/net.js
Related
I'm currently very interested in the comprehensive opportunites granted by electron.js and its modules. Unfortunately, I keep getting the same error in my renderer process (named 'connector.js') when trying to start my application.
Here is the error:
App threw an error during load
TypeError: Cannot match against 'undefined' or 'null'.
at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:2:44)
at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:22:3)
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.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\main.js:9:1)
And here is my connector.js:
const $ = require('jquery');
const {BrowserWindow} = require('electron').remote;
let Remotewin = remote.getFocusedWindow();
$("#minimize").click(function(){
Remotewin.minimize();
});
$("#maximize").click(function(){
if(!Remotewin.isMaximized()){
Remotewin.maximize();
}else{
Remotewin.unmaximize();
}
});
$("#close").click(function(){
Remotewin.close();
});
As you can see clearly, I wanted to create my own menubar at the top frame of the window, but the functionality is getting seemingly demolished by this error. I already searched half of the internet and stackoverflow, but the every answer I found refered to a webpack and/or electron bug they couldn't directly influence.
That's why I want to clearly point out, that I am NOT using webpack in this project. Only external module I added is jquery, as you can see in the code.
So my question; Have you experiended this error in this context and do you maybe even know a solution? Or can you refer to someone with similiar problems?
Thank you in advance, J0nny
Since getFocusedWindow() is a a static method of BrowserWindow,
let Remotewin = remote.getFocusedWindow();
should be:
let Remotewin = BrowserWindow.getFocusedWindow();
I am trying to run one of the sample projects using appjs which is present over here https://github.com/appjs/appjs/tree/master/examples. I am using the latest version of node.js (v4.1.0
) on Windows (64 bit machine)
When I try and run the example using the below command on Command Prompt
node --harmony index.js
I get an error as follows,
Error: AppJS requires Node is run with the --harmony command line flag
at Object.<anonymous> (F:\programs\appjs_examples\node_modules\appjs\lib\ind
ex.js:2:9)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452: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> (F:\programs\appjs_examples\octosocial\index.js:1:73)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
I tried searching for this issue but I couldn't find a solution. Can anyone tell me how to use node.js with the harmony flag?
UPDATE
My index.js looks like this
var app = require('appjs'),
github = new (require('github'))({ version: '3.0.0' }),
KEY_F12 = process.platform === 'darwin' ? 63247 : 123;
app.serveFilesFrom(__dirname + '/assets');
var window = app.createWindow({
width: 460,
height: 640,
resizable: false,
disableSecurity: true,
icons: __dirname + '/assets/icons'
});
window.on('create', function(){
window.frame.show();
window.frame.center();
});
window.on('ready', function(){
var $ = window.$,
$username = $('input[name=username]'),
$password = $('input[name=password]'),
$info = $('#info-login'),
$label = $info.find('span'),
$buttons = $('input, button');
$(window).on('keydown', function(e){
if (e.keyCode === KEY_F12) {
window.frame.openDevTools();
}
});
$username.focus();
$('#login-form').submit(function(e){
e.preventDefault();
$info.removeClass('error').addClass('success');
$label.text('Logging in...');
$buttons.attr('disabled', true);
github.authenticate({
type: 'basic',
username: $username.val(),
password: $password.val()
});
github.user.get({}, function(err, result) {
if (err) {
$info.removeClass('success').addClass('error');
$label.text('Login Failed. Try Again.');
$buttons.removeAttr('disabled');
} else {
loggedIn(result);
}
});
});
function loggedIn(result){
$label.text('Logged in!');
$('#user-avatar').append('<img src="'+result.avatar_url+'" width="64" height="64">');
$('#user-name').text(result.name);
$('#login-section').hide();
$('#profile-section').show();
['Followers', 'Following'].forEach(function(type){
github.user['get'+type]({ user: result.login }, populate.bind(null, type.toLowerCase()));
});
}
Now with v0.12 of Node.js I get below error
F:\softwares\Node.js_v0.12\node_modules\appjs\lib\index.js:2
throw new Error ('AppJS requires Node is run with the --harmony command line
Error: AppJS requires Node is run with the --harmony command line flag
at Object.<anonymous> (F:\softwares\Node.js_v0.12\node_modules\appjs\lib\ind
ex.js:2:9)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478: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> (F:\softwares\Node.js_v0.12\index.js:1:73)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Just tested your code out locally with node v0.12.7 and v4.0.0. Looks like the node_modules/appjs/lib/index.js check makes sure that proxy is enabled no matter what.
By default the --harmony flag does not enable proxies. However you can use --harmony_proxies.
To help you understand what is happening:
Open node in your terminal, Then type Proxy. You will get 'Proxy is not defined'.
Now, open node --harmony in your terminal and do the same. You will get the same output.
Now, with node --harmony-proxies. Bam, you get an empty object.
You should be able to run this with v4.x.x however, you will still need the proxies flag for harmony.
When the merge happened with node.js and io.js for v4 they released a page of ES6 features that are shipped if you are using 4.x.x. https://nodejs.org/en/docs/es6/
https://github.com/appjs/appjs is deprecated btw, but once you pass the module's test of features, it will require 32bit ;)
Edit:
To properly run your app use the following:
node --harmony-proxies index.js
Here is a screenshot to show the expected output from step 3 above.
I'm just trying to run html-snapshots. This should be easy, right?
This is what I started with:
npm install html-snapshots
That's all I need, right? Here's my snapshots.js file:
var htmlSnapshots = require('html-snapshots');
htmlSnapshots.run({
source: "sitemap.xml",
hostname: "localhost",
outputDir: "snapshots",
outputDirClean: true,
selector: "#results-widget"
});
And to run it:
node snapshots.js
But nooo:
module.js:340
throw err;
^
Error: Cannot find module '.\robots'
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.module.exports.create (C:\webdev\node_modules\html-snapshots\lib\input-generators\index.js:38:16)
at Object.module.exports.run (C:\webdev\node_modules\html-snapshots\lib\html-snapshots.js:42:39)
at Object.<anonymous> (C:\webdev\snapshots.js:2:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
wtf?
Additional Info...
This is part of html-snapshots.js:
var inputFactory = require("./input-generators");
...
run: function(options, listener) {
...
var inputGenerator = inputFactory.create(options.input);
...
result = inputGenerator.run(options, (function(options, notifier){
Also, the html-snapshots\lib\input-generators folder contains the file robots.js
It looks like an issue inside html-snapshots\lib\input-generators\index.js file - it works fine on Linux systems but fails on Windows (path.sep has been used to build module name)
Problem is that it should load './robots' module instead of '.\robots'.
Quick fix is to update html-snapshots\lib\input-generators\index.js file - line 38.
Change line:
result = require(file);
to:
result = require(path.join(__dirname, file));
And it will work fine. I hope that will help.
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.
I am loading a Node.js module using require. This throws a Syntax Error (an Error object).
Is there a way to get the location in the file where the error occurred?
I can see the stack (below) but I don't have any location information. I know I can use substack's node-syntax-error, but is there a way to get similar location info from the Javascript Error object?
SyntaxError: Unexpected identifier
at Module._compile (module.js:437:25)
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.require (module.js:362:17)
at require (module.js:378:17)
... // the rest is in my code
EDIT:
According to Vadim's comment below, yes that is what I am tempted to do. I see that node throws nice errors. Having a test.js file that contains only abc you get an error from node saying
ReferenceError: abc is not defined
at Object.<anonymous> (test.js:1:63)
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:901:3
Now the question is, is there a node API to do get this error (that the node module.js module uses) such that I don't have to child_process.spawn('node', ['test.js'])?
You can simple run node with file that contains SyntaxError and see console output.
Error.stack
Errors have a "stack" property that stores the stack trace.
try {
throw new Error("with some message");
}
catch(err) {
// print error's stack trace to stder
console.error(err.stack);
}
running this on a file called "/home/myusername/test.js"
node /home/myusername/test.js
will output the following
Error: with some message
at Object.<anonymous> (/home/myusername/test.js:2:11)
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:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
#laconbass answer works for me.
err.stack
I tried a blog framework and I got : 500 Internal Server Error. Hopefully I put a console :
app.use(function(error, req, res, next) {
res.status(500).render('500');
console.log(error);
});
and I could see the error which was not descriptive:
TypeError: Cannot read property 'replace' of undefined
After several minuts of research I found this answers, So I tried :
app.use(function(error, req, res, next) {
res.status(500).render('500');
console.log(error.stack);
});
and I could see the source point of error : (Object.exports.replace)
TypeError: Cannot read property 'replace' of undefined
at Object.exports.replace (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/filters.js:411:15)
at eval (eval at <anonymous> (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:498:13), <anonymous>:41:63)
at Object.exports.each (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/utils.js:45:11)
at eval (eval at <anonymous> (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:498:13), <anonymous>:26:10)
at Object.eval [as tpl] (eval at <anonymous> (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:498:13), <anonymous>:85:3)
at compiled (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:619:18)
at /.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:559:20
at /.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:690:9
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
I know that this is not a syntax error, but could be works to find the location of a javascript/node error.
I am a novice in nodejs.
I hope this helps.
You can use the stacktracey library (note: I'm the author of this library).
It prints nice callstacks along with source code lines, and also parses the SyntaxError output (in Node higher than v4).
For example, when trying to require this file (named test_files/syntax_error.js):
// next line contains a syntax error (not a valid JavaScript)
foo->bar ()
...the pretty printed call stack for the error thrown would be:
at (syntax error) test_files/syntax_error.js:2 foo->bar ()
at it test.js:184 try { require ('./test_files/syntax_error.js') }
at runCallback timers.js:781
at tryOnImmediate timers.js:743
at processImmediate [as _immediat timers.js:714
...where the first line is generated from parsing the raw output from the util.inspect call in Node.
The library also provides the full API access to the contents of a parsed call stack, so you can tune the output to whatever you want.