I am trying phantomjs in MEAN stack for report generation but after installing phantom binaries in my ubuntu os server and using phantom node_module + rasterize.js throws below error.
Error: Cannot find module 'events'
phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:1
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:126
Error: Cannot find module 'stream'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/lib/dnode.js:2
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/lib/dnode.js:154
Error: Cannot find module 'net'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/index.js:3
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/index.js:138
Error: Cannot find module 'http'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/phantom.js:8
/home/kb/code/backend/backend/api_server/node_modules/phantom/phantom.js:193
/home/kb/code/backend/backend/api_server/node_modules/phantom/phantom.js:194
TypeError: 'undefined' is not a function (evaluating 'phantom.createWebPage()')
:/modules/webpage.js:905
report.js:7
This is my test code.
var phantom = require('phantom');
phantom.create(function (ph) {
ph.createPage(function (page) {
page.open("http://www.google.com", function (status) {
console.log("opened google? ", status);
page.evaluate(function () { return document.title; }, function (result) {
console.log('Page title is ' + result);
ph.exit();
});
});
});
});
Try run command:
npm install -g events stream net http
However, I think that you did wrong way to setup a Node Project. For example, If you want to create a project requires PhantomJS. You should do the steps below:
# create project directory
mkdir myproject
cd myproject
# install phantomjs for your project
npm install --save phantomjs
# create your project file
Related
I'm new to Node.js and react-native. I followed the sample on send_telemetry.js exactly but when I run my react-native app I get an error: "The development server returned response error code 500.
the error message is:
bundling failed: Error: Unable to resolve module fs from ProjectPath\node_modules\azure-iot-device\lib\module_client.js: Module fs does not exist in the Haste module map";
Im running:
Node.js v10.15.3
NPM 6.4.1
react-native#0.59.2
First error was the same with Unable to resolve module events,
I can install events,
but the fs module is: "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it."
var Protocol = require('azure-iot-device-http').Http;
var DeviceClient = require('azure-iot-device').Client;
var Message = require('azure-iot-device').Message;
var connectionString = 'my connection string';
var client = DeviceClient.fromConnectionString(connectionString, Protocol);
function ConnectionTest(err) {
if (err) {
console.log('Could not connect: ' + err);
} else {
console.log('Client connected');
}
client.close(function () {
process.exit(0);
});
};
export async function Test() {
client.open(ConnectionTest);
};
Basically I need to know how to get the azure IOT hub client working in my react-native app (not using Expo).
Im pretty much stumped so any help would greatly be appreciated.
A dependency module is missing ... which is fs ...
this file-system npm module is incompatible with react-native ... cause it has it own different environment.
I had "import { symlink } from 'fs';" randomly pop up in one of my scripts. Once I deleted this line same issue you had went away. I would search your whole project for that line.
I am trying to use ganache and web3.js inside Token wizard application.
I run an instance of the ganache-cli in my terminal and then create an instance of web3.js using ganache as a provider using this code:
try {
window.web3 = new Web3(window.web3.currentProvider)
this.setState({
approvePermissions: true,
web3: window.web3
})
} catch (err) {
console.log('There was a problem fetching accounts', err)
}
as I launch my application, I get the following error:
Error in ganache-cli
Module not found: Error: Can't resolve 'child_process' in 'C:\Users\name\Desktop\wiz\node_modules\ganache-cli\build'
Any one has idea to solve it?
Why do I get this error?
Node v8.9.1
code
var childProcess = require('child_process'),
phantomjs = require('/var/bin/node_modules/phantomjs-prebuilt');
console.error = function(){
require('system').stderr.write(Array.prototype.join.call(arguments, ' ')+'\n');
phantomjs.exit(1);
};
console.log('hey', phantomjs.path)
console.error('error')
childProcess.execFile(phantomjs.path, require('system').args, function(err, stdout, stderr){
if(err){
console.error(err);
}
if(stderr){
console.error(stderr);
}
console.log(stdout);
});
error
# /var/bin/node_modules/phantomjs-prebuilt/bin/phantomjs phantom.js
Error: Cannot find module 'path'
phantomjs://platform/bootstrap.js:299 in require
phantomjs://platform/bootstrap.js:263 in require
phantomjs://platform/phantomjs.js:10
hey undefined
TypeError: undefined is not a function (evaluating 'phantomjs.exit(1)')
phantomjs://code/phantom.js:6 in error
error
system is not a Node built-in module, it's part of PhantomJS. It won't be available if you're just running your script with the standard node command. As shown in the documentation, you need to use the phantomjs command, like so:
phantomjs phantom.js
I'm using Typings in one of my TypeScript projects. I'm having a problem when running the command to install type definitions:
$ node_modules/.bin/typings install
typings ERR! message Unable to read typings for "angular". You should check the entry paths in "angular.d.ts" are up to date
typings ERR! caused by Unable to connect to "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7ce80dafc0df189d61950e80e04548d8304d1538/angularjs/angular.d.ts"
typings ERR! caused by getaddrinfo ENOTFOUND raw.githubusercontent.com raw.githubusercontent.com:443
It would seem that it can't get angular.d.ts (ENOTFOUND). But I'm confused by this, because I can get that just fine with curl:
$ curl "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7ce80dafc0df189d61950e80e04548d8304d1538/angularjs/angular.d.ts"
// Type definitions for Angular JS 1.4+
// Project: http://angularjs.org
. . .
Any ideas? Why is typings/node not able to find the type defs?
Node 6.3.0
Typings 1.3.2
npm 3.10.5
EDIT
I made a simple node script to try to reproduce the problem. Unfortunately, I was not able to reproduce it - this script works fine, even though typings install consistently produces the error.
var https = require('https');
var options = {
host: 'raw.githubusercontent.com',
path: '/DefinitelyTyped/DefinitelyTyped/7ce80dafc0df189d61950e80e04548d8304d1538/angularjs/angular.d.ts',
port: 443
};
var req = https.get(options, function(res) {
var str = '';
console.log(options.host + ':' + res.statusCode);
res.on('data', function(chunk) {
str += chunk;
});
res.on('end', function() {
console.log(str);
});
}).on('error', function(err) {
console.log('ERROR! ' + err);
});
EDIT 2
wget fails with an error about a certificate. Not sure if this is at all related:
$ wget "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7ce80dafc0df189d61950e80e04548d8304d1538/angularjs/angular.d.ts"
--2016-08-16 20:00:13-- https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7ce80dafc0df189d61950e80e04548d8304d1538/angularjs/angular.d.ts
Resolving raw.githubusercontent.com... 151.101.48.133
Connecting to raw.githubusercontent.com|151.101.48.133|:443... connected.
ERROR: certificate common name “www.github.com” doesn’t match requested host name “raw.githubusercontent.com”.
To connect to raw.githubusercontent.com insecurely, use ‘--no-check-certificate’.
We are using AMD modules in our project. I want to use a 3rd party commonJS module that is installed through npm install. I had a problem which shim. Hence trying another strategy to use commonJS module in my requireJS build.
So, I am trying to use instructions mentioned here to declare my commonJS module in my AMD build. Here I am facing a different problem. Although I see the r.js is able to load node module in gulp process, its not able to load node module when exceuting
// NOT WORKING. WHY ??
requirejs.optimize(config, function(buildResponse){
console.log('build response', buildResponse);
}, cb);
Here is my full gulp file :
var gulp = require('gulp');
var requirejs = require('requirejs');
config = {
name: 'src/app',
baseUrl: ".",
out: 'dist/app.build.js',
nodeRequire: require,
paths: {
"jquery": "lib/jquery-1.12.0",
"underscore": "lib/underscore"
}
};
requirejs.config(config);
gulp.task('requirejs', function (cb) {
// WORKING: r.js is able to load dagre-d3 in commonJS path
console.log('1.5 dagreD3: ' + requirejs('dagre-d3'));
// WORKING: r.js is able to load dagre-d3 in commonJS path
requirejs(['dagre-d3'], function ( dagreD3 ) {
console.log('2 dagreD3: ' + dagreD3);
});
// NOT WORKING. WHY ??
requirejs.optimize(config, function(buildResponse){
console.log('build response', buildResponse);
}, cb);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['requirejs']);
Here is my git repo illustrating the problem.
Following is the error iam getting while executing gulp:
[11:30:55] Starting 'requirejs'...
1.5 dagreD3: [object Object]
[11:30:55] 'requirejs' errored after 339 ms
[11:30:55] Error: Error: ENOENT: no such file or directory, open '/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/dagre-d3.js'
In module tree:
src/app
at Error (native)
at /Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:25150:19
at /Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:3056:39
at /Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:2996:25
at Function.prim.nextTick (/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:24901:9)
at Object.p.errback (/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:2995:26)
at Object.p.callback (/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:2981:23)
at Object.p.promise.then (/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:3035:23)
at build (/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:25107:12)
at runBuild (/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:27115:17)
at Object.context.execCb (/Users/akandregula/arun/amd-practice/using_commonJS_module_with_amd/node_modules/requirejs/bin/r.js:1943:33)
2 dagreD3: [object Object]