I'm writing a GitHub action that receives a mandatory input field named file using #actions/core library.
const core = require("#actions/core");
async function run() {
try {
let file = core.getInput('file', {required: true});
// rest of my action ...
I'm able to run it locally and it fails as expected as-is (no input provided).
Is there a built-in way to provide inputs (similar to env-vars) so I could run and test it locally?
Error: Input required and not supplied: file
at Object.getInput (.../node_modules/#actions/core/lib/core.js:78:15)
at run (.../src/main.js:6:25)
at Object.<anonymous> (.../src/main.js:40:5)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
::error::Input required and not supplied: file
If you look at the sources of getInput, you can see that it is using environment variables:
const val: string =
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
Knowing this, you can just set this environment variable:
const setInput = (name,value)=>
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`]=value;
Related
I have a file for my Blockchain called gale.js, and I need the Blockchain variable to get into my miner.js file:
let galeCoin = new Blockchain(); // My Blockchain
Can I access this variable from my miner.js file so I can run the minePendingTransactions() function from the Blockchain class
var galeCoin = /* the coin imported from the gale.js file */
var minerAdress = "0xOTUYboIUYEO5C274OUIYGo8isYOCYW6o87TO"; // SHA256 Hash for the miner
while (true) {
minePendingTransactions(minerAdress); // mine (forever)
}
I would also like to access this variable in my user.js file:
var galeCoin = /* the coin imported from the gale.js file */
var userAdress = galeCoin.newAdress(); // A new adress for the user
// I will add the code here later...
And many other files!
But I can't seen to access the variable from the other files!
I tried this:
let galeCoin = new Blockchain();
export { galeCoin };
import { galeCoin } from './gale.js'
but that gives me this error when I run miner.js using node miner.js:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'gale.js'
Require stack:
- /Users/Movies/Desktop/devProjects/Blockchain/SecondTry/miner.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/Movies/Desktop/devProjects/Blockchain/SecondTry/miner.js:1:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/Movies/Desktop/devProjects/Blockchain/SecondTry/miner.js' ]
}
I dont understand the error message
I need help as soon as posible!
NOTE: My files are in /Users/Movies/Desktop/devProjects/Blockchain/SecondTry/
Try using the following to import galeCoin from gale.js:
var {galeCoin} = require('./gale.js');
You'll also need to export the galeCoin object from gale.js. You can use the following (append somewhere at the end of gale.js):
module.exports = {galeCoin};
Then you're going to want to run npm install gale.js to ensure that module is added to the node_modules directory. For this you're going to want to make sure the node_modules is in the same director as miner.js. If it is not, npm -g install gale.js.
I should note, I'm assuming you're using node.js, which from the error you threw, seems to be the case.
I hope this was helpful:)
Try :
export let galeCoin = new Blockchain();
//add export statement at the beginning of the line where you declare your variable
You can read about it here: https://javascript.info/import-export
I'm trying to familiarise myself with HapiJS and have been playing around with it this week, I've run into a problem with plugins and paths. I get an error regarding the path I specify when I require a file. I can't use " ./ " without getting an error. The only way to overcome the error is to use the full complete path.
Here's my code that works:
'use strict';
const indexController = require('/Users/mylaptop/docker-node/controllers/IndexController.js');
module.exports.plugin = {
name: 'myPlugin',
version: '1.0.0',
register: async function (server, options) {
// Create a route for example
server.route({
method:'GET',
path:'/test',
handler: function (request, h) {
return indexController.loadIndex(h);
}
});
}
};
However, if I try to require my IndexController file this way:
const indexController = require('./controllers/IndexController.js');
Then I get this error:
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '/Users/mylaptop/docker-node/Users/mylaptop/docker-node/controllers/IndexController.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/mylaptop/docker-node/config/routes/index.js:5:25)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
It doesn't work inside of my plugin, yet outside of my plugin, requiring files this way works fine.
What could be the problem? How can I solve it?
Thanks in advance.
Problem solved with:
const indexController = require('../../controllers/IndexController.js');
My project root folder was 2 directories away, hence ../../ working for me.
If I try to create a bitpay client in node after npm install bitpay and feeding it my on bitpay.com generated api key.
var client = BitPay.createClient('apikey');
I get:
assert.js:92 throw new assert.AssertionError({
AssertionError: Not enough entropy. Minimum is: 192 bits
at new HmacDRBG (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/node_modules/bitauth/node_modules/elliptic/lib/elliptic/hmac-drbg.js:24:3)
at EC.sign (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/node_modules/bitauth/node_modules/elliptic/lib/elliptic/ec/index.js:94:14)
at Object.BitAuth.sign (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/node_modules/bitauth/lib/bitauth.js:101:25)
at RESTClient._sendRequest (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:156:46)
at RESTClient.get (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:282:28)
at RESTClient._getAccessTokens (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:81:19)
at new RESTClient (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:51:17)
at Object.module.exports.createClient (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/index.js:10:12)
at Object.<anonymous> (/home/enigma/WebstormProjects/expensereports/server/api/btc/btc.controller.js:6:21)
at Module._compile (module.js:456:26)
if I try the website provided way:
$ npm install bitpay
var BitPay = require('bitpay');
var client = new BitPay('apikey');
client.on('ready', function() {
client.post('invoices', { price: 10.00, currency: 'USD' });
});
it complains
var client = new BitPay('apikey'
TypeError: object is not a function
at Object.<anonymous> (/home/enigma/WebstormProjects/expensereports/server/api/btc/btc.controller.js:6:14)
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)
at Object.<anonymous> (/home/enigma/WebstormProjects/expensereports/server/api/btc/index.js:4:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
I also tried a couple of other ways non of them worked so my question how am I supposed to connect to this service?
If I use bitpay keygen to create a api.key file locally. How could I set this in my settings on bitpay.com to avoid {“error”: “Invalid token”}?
There's a realistic possibility this API token is invalid. The 1st error message displayed means the API token's length is way too short and therefore invalid. Please verify you entered the correct API keys and enter it as a string. Are you sure you didn't remove the first character of the token when copying and pasting? Are you sure you didn't pick the wrong token? Example:
var client = new BitPay('MY_192_BIT_HUGE_API_TOKEN'); //192 bit string
Best regards,
I am working through Brad Dayley's Node.js, MongoDB and Angularjs book and I'm stuck on one of his exercises (Listing 4.4). I have a simple script emitterListener.js that is as follows the script is designed to makes checks on an account.
var events = require('events');
function Account() {
this.balance = 0;
events.EventEmitter.call(this);
this.deposit = function(amount) {
this.balance += amount;
this.emit('balanceChanged');
};
this.withdraw = function(amount) {
this.balance -= amount;
this.emit('balanceChanged');
};
}
Account.prototype._proto_ = events.EventEmitter.prototype;
function displayBalance() {
console.log("Account balance: $%d", this.balance);
}
function checkOverdraw() {
if (this.balance < 0) {
console.log("Account Overdrawn!!!!!");
}
}
function checkGoal(acc, goal) {
if (acc.balance > goal) {
console.log("Goal Achieved!!!!!");
}
}
var account = new Account();
account.on("balanceChanged", displayBalance);
account.on("balanceChanged", checkOverdraw);
account.on("balanceChanged", function() {
checkGoal(this, 1000);
});
account.deposit(220);
account.deposit(320);
account.deposit(600);
account.withdraw(1200);
When I run this I get the error.
TypeError: Object #<Account> has no method 'on'
at Object.<anonymous> (/Users/506132/web/emitterListener.js:35:9)
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:906:3
From my limited understanding after researching I think this means that the "on" module is not being loaded. I found a solution that suggested something similar to adding this to line 1
var events = require('events').on;
which then results in the error.
TypeError: Cannot read property 'EventEmitter' of undefined
at Object.<anonymous> (/Users/506132/web/emitterListener.js:16:35)
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:906:3
Following the logic from the first fix I tried implementing the same fix but with EventEmitter
var events = require('events').EventEmitter;
Hooray it looks like it worked.... or not......and now I get this error
TypeError: Cannot read property 'prototype' of undefined
at Object.<anonymous> (/Users/506132/web/emitterListener.js:17:48)
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:906:3
I tried adding the below code thinking why not?
var events = require('events').prototype;
and it just brings me back to the same error from before
TypeError: Cannot read property 'EventEmitter' of undefined
at Object.<anonymous> (/Users/506132/web/emitterListener.js:16:35)
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:906:3
What am I doing wrong here? How should I go about debugging this and where should I look? Thanks in advance for helping a newbie out.
Cheers.
process.EventEmitter is deprecated, use require('events') instead.
Search through all your reference files (should be in multiple files) for:
var EventEmitter = process.EventEmitter
An where ever it exists, change that line to this:
var EventEmitter = require('events')
I'll post it as an answer so this question won't get marked as unanswered.
You should change:
Account.prototype.__proto__ = events.EventEmitter.prototype;
to:
Account.prototype = Object.create(events.EventEmitter.prototype);
var EventEmitter = process.EventEmitter
is deprecated in high version of node, use var EventEmitter = require('events') instead
This compilation error because of versions conflicts of npm and node. I had the same issue in my project. I resolved after install the same compatible versions of npm and node as on another machine.
Check:
nmp -v
and
node -v.
All the confusion with the actual example is the first line of code.
var events = require('events');
After Node v6.1.0 this line of code will store EventEmmiter object inside events variable, so there is no need to access it explicitly later.
Solution is very simple, just change
events.EventEmitter.call(this);
to:
events.call(this)
And change
Account.prototype._proto_ = events.EventEmitter.prototype;
to:
Account.prototype._proto_ = events.prototype;
I had the same problem a few minutes ago, I decided to downgrade node to version 6.x, then it worked
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.