var fs = require('fs');
var socks = require('socks');
var proxies = fs.readFileSync('proxies.txt').replace(/\r/g, '').split('\n');
function createAgent() {
var proxy = proxies[Math.floor(Math.random() * proxies.length)];
return new socks.Agent({
ipaddress: proxy[0],
port: proxy[1],
type: 5
});
}
Socks module has changed the libraries and this script wont work anymore.
Can anybody help me and explain this ?
I didn't expect to see you here, I was having the same problem but then I read your question and you stated
Socks module has changed the libraries
That gave me the idea to install an older version of socks.
npm install socks#1
And that worked. It worked for me, it should work for you.
Related
I'm using chalk version ^1.1.3
No idea why it's saying that the method is not recognized:
const chalk = require('chalk'),
_ = require('lodash'),
info = chalk.yellow,
green = chalk.green,
script = chalk.bgHex('#ebd2f8')
Error: chalk.bgHex is not a function
I also don't know how I'd append a text color on top of that background.
The commit that introduced hex/bgHex was committed just 2 hours ago. There hasn't been a new publish to the NPM repository with that commit.
If you want to use it, you can use the GitHub-hosted version of the module:
$ npm i chalk/chalk
However, do so with extreme caution. There's probably a reason why the developers haven't published a new version yet (i.e. it's not finished).
I just wondered if it is possible to make systemjs use require("remote").require("nodemodule"), if system js can't find the module in its own registry?
I think something like this mechanism is already working when using electron with typescript and commonjs modules...
Has someone already solved that struggle?
Finally after some time I found a working solution:
var node_modules = ["child_process","fs"];
var fetch = System.fetch;
window.remote=require("remote");
System.fetch = function () {
var promise= fetch.apply(System,arguments);
return promise.then(function (js) {
for(var m of node_modules){
var requireExpression = 'require("'+m+'");';
var remoteRequire = 'remote.require("'+m+'");'
js=js.replace(requireExpression,remoteRequire);
}
return js;
});
}
System.import("aurelia-bootstrapper");
Just add all imported node_modules to the array and things are fine
I have tests for an addon which pass in chrome, but fail in phantomjs.
It seems to be a problem similar to this question. However, I tried the solution there and it didn't work for me.
The code is all available in the public repo linked above. The failures are exhibited in the failing travis build on github. Any ideas on how to diagnose better and fix?
EDIT -- actual error message
Died on test #1 at http://localhost:7357/assets/test-support.js:3062
at test (http://localhost:7357/assets/test-support.js:1945)
at test (http://localhost:7357/assets/dummy.js:2090)
at http://localhost:7357/assets/dummy.js:2885
at http://localhost:7357/assets/vendor.js:150
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:6775: Can't find variable: Symbol
UPDATE
Following up on a hint from #knownasilya, I tried forcing optional babel transform es6.spec.symbols on: in ember-cli-build.js:
module.exports = function(defaults) {
var app = new EmberAddon(defaults, {
// Add options here
+ babel: {
+ optional: ['es6.spec.symbols']
+ }
});
However -- no luck. It does look like an es6 transpilation problem, though. Did I not pass the option successfully? Any other hints? I'll be happy to post code snippets if you don't want to look in the repo. :)
UPDATE 2
Including as well:
+ includePolyfill: true
works!
Now I'm on to:
ReferenceError: Can't find variable: requestAnimationFrame
I'm looking for a polyfill for this as well... but looking at the testem configuration for ember-collection, which seems to have a similar configuration, I notice that phantomjs testing is turned off! Now the question is: best way to test requestAnimationFrame in phantomjs?
The offending culprit is Can't find variable: Symbol, which is an ES2015 (ES6) feature, which is why the es5 shim didn't work for you.
Since babel doesn't include polyfills by default, you need to force ember-cli-babel to include the polyfills.
// ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
const app = new EmberApp(defaults, {
'ember-cli-babel': {
includePolyfill: true
}
});
return app.toTree();
};
For details of the available options, see https://github.com/babel/ember-cli-babel#options
For a more comprehensive solution, give babel6 (https://github.com/ember-cli/ember-cli/pull/6828) and targets (https://github.com/ember-cli/ember-cli/pull/6776) a try.
Note: The polyfill includes core.js which includes Symbols.
Jasmin methods (i.e. createSpyOjb) are not recognized though I've added a definition file.
Any idea why is that happening?
I have the below code working perfectly with the latest definitions from Definitely Typed.
/// <reference path="node.d.ts" />
/// <reference path="jasmine.d.ts" />
var fs = jasmine.createSpyObj('fs', ['readfile']);
var callback = jasmine.createSpy('callback');
var rek = require('rekuire');
var proxykuire = rek('proxykuire').proxykuire;
var getMenuDataCommand = rek('GetMenuDataCommand');
describe('GetMenuDataCommand', function () {
var getMenuDataCommand;
var fs;
var callback;
beforeEach(function () {
fs = jasmine.createSpyObj('fs', ['readFile']);
callback = jasmine.createSpy('callback');
var getMenuDataCommand = proxykuire('GetMenuDataCommand', { fs: fs });
getMenuDataCommand = new getMenuDataCommand();
});
});
The only difference (unless I typed something in wrong) is that my references are closer to my TypeScript file. I get full intelliSense and no errors.
WebStorm
I just tested in WebStorm and it doesn't seem to support TypeScript 0.9, which will be a stumbling block if you use WebStorm. (It didn't recognise the boolean type and hasn't got the export = internal; support).
You could use older versions of the definitions (from before they were updated to TypeScript 0.9) to get you going for now and then update when WebStorm gets 0.9 language support.
For WebStorm, refer to this documentation: https://www.jetbrains.com/webstorm/webhelp/configuring-javascript-libraries.html, section Downloading and installing a JavaScript-related library from WebStorm
More information about Typescript support:
https://www.jetbrains.com/webstorm/webhelp/typescript-support.html
TL;DR; WebStorm doesn't seem to understand <reference> yet. Configure JavaScript libraries on WebStorm settings.
I am a NodeJS newbie and JS can-kicker trying out DI for the first time. Here are the questions I looked at before deciding to ask mine, since they show the same error: [1][2]
Running my entry point yields:
this.client = new MongoClient(server);
^
TypeError: undefined is not a function
Entry point
var config = require('./config.json');
var Providers = require('./providers');
var providers = new Providers(config.db);
console.log(providers);
./providers/index.js
Both AssetProvider and UserProvider suffer the same error. I think I only need to show one.
module.exports = function Provider(dbConfig)
{
var UserProvider = require('./userProvider');
var AssetProvider = require('./assetProvider');
this.users = new UserProvider (dbConfig.name, dbConfig.host, dbConfig.port);
this.assets = new AssetProvider(dbConfig.name, dbConfig.host, dbConfig.port);
}
./providers/userProvider.js
Problem line marked
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var Server = mongodb.Server;
var ObjectID = mongodb.ObjectID;
var UserProvider = function (database, host, port) {
var server = new Server(host, port, { auto_reconnect: true });
// Error is here
this.client = new MongoClient(server);
this.client.open(function (error, client) {
this.db = client.db(database);
});
};
// ...a bunch of prototype stuff...
// ...
module.exports = UserProvider;
From what I have read in other locations online, I don't see anything wrong with my syntax. I have tried the following declaration...
function UserProvider(database, host, port)
as opposed to
var UserProvider = function(database, host, port)
Everything else I did was comparable to slapping a car engine with a wrench. The truth is, I simply do not understand what is so wrong here, but I do know that I just want to make a composition of objects across files so that my entry point can readily use all providers through a single object.
JohnnyHK turned out to be correct about it being a version issue.
Oddly enough, the error did not go away when running npm update mongodb
However, it did go away when I ran npm install mongodb a second time.
No changes were made in the code, and mongodb was already inside the local
node_modules folder. Even so, I suspect this had to do with a discrepancy between an instance in node_modules and an instance in NODE_PATH.
I'm only speculating as to why exactly npm install solved the problem considering the latest version should have been installed. All I know is that the error is gone and the code is working.
Thank you for the comments!
I got exactly the same issue. After a quick research I realised that I have an old mongodb module version (0.9.x). After installing the latest (1.13.19) - the issue has been fixed.
npm install mongodb#1.3.13