I was trying to build a Slack Bot in Node but always seem to get this error when I run npm start in my terminal :
It shows an error in the Vow.js file. I checked everything twice but can't find the problem. For reference, I was following along this youtube toturial from Brad Traversy https://www.youtube.com/watch?v=nyyXTIL3Hkw
> alfalfa#1.0.0 start /Users/ayushpathak/Documents/alfalfa
> node index.js
/Users/ayushpathak/Documents/alfalfa/node_modules/vow/lib/vow.js:105
throw e;
^
Error: not_allowed_token_type
at /Users/ayushpathak/Documents/alfalfa/node_modules/slackbots/index.js:46:33
at Array.<anonymous> (/Users/ayushpathak/Documents/alfalfa/node_modules/vow/lib/vow.js:773:56)
at callFns (/Users/ayushpathak/Documents/alfalfa/node_modules/vow/lib/vow.js:24:35)
at processTicksAndRejections (node:internal/process/task_queues:75:11)
Emitted 'error' event on Bot instance at:
at /Users/ayushpathak/Documents/alfalfa/node_modules/slackbots/index.js:46:19
at Array.<anonymous> (/Users/ayushpathak/Documents/alfalfa/node_modules/vow/lib/vow.js:773:56)
at callFns (/Users/ayushpathak/Documents/alfalfa/node_modules/vow/lib/vow.js:24:35)
at processTicksAndRejections (node:internal/process/task_queues:75:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! alfalfa#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the alfalfa#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ayushpathak/.npm/_logs/2021-01-24T08_41_17_374Z-debug.log
Here's package.json :
"name": "alfalfa",
"version": "1.0.0",
"description": "a slackbot that does, well, everything",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "Ayush Pathak",
"license": "MIT",
"dependencies": {
"axios": "^0.21.1",
"slackbots": "^1.2.0"
}
}
Here's index.js
const SlackBot = require('slackbots');
const Axios = require('axios');
const bot = new SlackBot({
token : 'I PUT THE TOKEN HERE',
name : 'alfalfa_beta',
});
bot.on('start', () => {
const params ={
icon_emoji : ":eyes:"
}
bot.postMessageToChannel('general', 'Initiated!')
})
So the token that needed to be added in slackbot is the jwt-token you get from https://api.slack.com/ when you are creating a new bot/app it cannot be any random string.
You can get the rest necessary details over here https://api.slack.com/methods/apps.permissions.info
Related
I am getting the following error while trying to deploy a Mock contract on the hardhat development chain.
I am following:
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course by Patrick Collins on FreeCodeCamp YT channel
I got this error while I was at 10:48:53 of the above course. I tried almost every thing but nothing helped but I found where the problem was occurring.
Ques: Where do I think the problem is occurring? (12:26)
According to me the problem is at the line where we are trying to deploy the script and we are waiting for the promise to be returned.
Here is the error:
Error: ERROR processing /Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/deploy/00-deploy-mocks.js:
TypeError: Cannot read property 'length' of undefined
at getFrom (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
at _deploy (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/helpers.ts:533:9)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at _deployOne (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/helpers.ts:1004:16)
at Object.module.exports [as func] (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/deploy/00-deploy-mocks.js:12:26)
at DeploymentsManager.executeDeployScripts (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
at DeploymentsManager.runDeploy (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at DeploymentsManager.executeDeployScripts (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at DeploymentsManager.runDeploy (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
at SimpleTaskDefinition.action (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/index.ts:438:5)
at Environment._runTaskDefinition (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/index.ts:584:32)
at Environment._runTaskDefinition (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at SimpleTaskDefinition.action (/Users/rishavsharma/Documents/working/Web Dev/Blockchain/Freecodecamp/solidity&Block/blockchain-with-js/buyMeACoffee-dapp/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
rishavsharma#Rishavs-Air buyMeACoffee-dapp %
Here is the code snippet in which I am getting the error:
const { network } = require("hardhat");
const { developmentChains, DECIMALS, INITIAL_ANSWER } = require("../helper-hardhat-config");
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
if (chainId == 31337) {
console.log("Development network detected! Deploying mocks...");
const feedMock = await deploy("MockV3Aggregator", {
contract: "MockV3Aggregator",
from: deployer,
log: true,
args: [DECIMALS, INITIAL_ANSWER],
});
log("Price Feed Mock deployed!");
log("==============================================");
}
}
module.exports.tags = ["all", "mocks"];
Please help me with this problem 🥹
I posted this question on Ethereum Stack Exchange but got no help.
System configuration: MacBook Air M1 2021 - Monterey 12.4, yarn: 1.22.18, Hardhat: 2.9.6
I got the answer from the MASTER himself, #PatrickAlphaC.
When we call await getNamedAccounts in the above code, hardhat looks for the length of the named accounts in our hardhat.config.js
We have to make sure that the property given below is in there!
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
},
},
This solved my problem and I was HAPPY again!
Make sure you have await in getNamedAccount(). Also name must be correct.
Must have correct entry for named accounts as below:
namedAccounts: {
deployer: {
default: 0,
deployer
1: 0,
},
},
I was stuck for a while with this as well, and was also following this same course.
Cannot read properties of undefined (reading 'length')
at getFrom (/Users/ilima/hh-fcc/hardhat-fundme-fcc/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
at _deploy (/Users/ilima/hh-fcc/hardhat-fundme-fcc/node_modules/hardhat-deploy/src/helpers.ts:533:9)
Initially I was writing from scratch and kept getting this error and plus hardhat npm installation. I decided to test just in case the course code, so I cloned the repo and surprisingly was also struggling with npm install issues for hardhat and waffle.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: hardhat-project#undefined
npm ERR! Found: #nomiclabs/hardhat-ethers#0.3.0-beta.13
npm ERR! node_modules/#nomiclabs/hardhat-ethers
npm ERR! dev #nomiclabs/hardhat-ethers#"npm:hardhat-deploy- ethers#^0.3.0-beta.13" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer #nomiclabs/hardhat-ethers#"^2.0.0" from #nomiclabs/hardhat-waffle#2.0.2
npm ERR! node_modules/#nomiclabs/hardhat-waffle
npm ERR! dev #nomiclabs/hardhat-waffle#"^2.0.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
So fixing dependency hardhat-ethers by overriding it, fixed all issues for me, so try this:
"devDependencies": {
...
"#nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers#^0.3.0-beta.13",
...
},
"overrides": {
"#nomiclabs/hardhat-waffle": {
"#nomiclabs/hardhat-ethers": "$#nomiclabs/hardhat-ethers"
}
}
I got solution from Installation advice breaks #nomiclabs/hardhat-waffle
Now, I noticed that you have already solved your problem, but I wanted to add my solution as well just in case if someone else is struggling with deploy being undefined in terminal. In my case namedAccounts and await getNamedAccount() was fine.
I am currently working on inserting a uuid-value like this one:
c1f9ff70-71e8-11eb-8b1b-77c34b246f91
into a sqlite database. This is my insert-Statement:
this.db.serialize(() => {
this.db.prepare(`CREATE TABLE IF NOT EXISTS bestellung(bid BLOB PRIMARY KEY, drink TEXT,price REAL,validation TEXT)`).run().finalize();
});
//FUNKTIONIERT!
const bidJSON = getBID();
const name = 'Testdrink';
const preis = 12.90;
const kpreis = preis.toFixed(2);
preis.toFixed(2);
console.log(bidJSON.id);
console.log(name);
console.log(kpreis);
var statement = "INSERT INTO bestellung(bid, drink, price, validation) VALUES(`" + bidJSON.id + "`,`" + name + "`,`" + kpreis + "`, `pending`)";
this.db.prepare(statement);
This is the error I get:
[Error: SQLITE_ERROR: no such column: c1f9ff70-71e8-11eb-8b1b-77c34b246f91
Emitted 'error' event on Statement instance at:
] {
errno: 1,
code: 'SQLITE_ERROR'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bk#0.0.0 start: `node app`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bk#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\prakt\AppData\Roaming\npm-cache\_logs\2021-02-18T12_56_46_751Z-debug.log
I hope someone can help me!
For experienced programmers it should be an easy task.
I think it will probably be a mistake in my statement. I already read, that you can save the uuid into a blob and that this is the fastest way of saving it...
so i would like to stick to that.
Thank you in advance!
I'm trying to connect Firebase using node.js
I have following code in my json file.
const functions = require('firebase-functions');
const hmac_sha256= require ('crypto-js/hmac_sha256');
const request= require('request');
const admin= require('firebase-admin');
const service_Account= require('./service_account_key.json');
const firebaseConfig= json.parse(process.env.FIREBASE_CONFIG);
firebaseConfig.credential= admin.credential.cert("service_Account");
admin.initializeApp(firebaseConfig);
exports.getCustomToken = functions.https.onRequest((req,res)=>{
const accessToken= req.query.access_Token;
const FacebookAppSec= '72100b8d4ee21a85fc67d014f3b0c9fa';
const AppSecretProof= hmac_sha256(accessToken,FacebookAppSec);
//Validate token...
const uri='https://graph.accountkit.com/v1.1/me?access_Token=${accessToken}&App_Proof=${AppSecretProof}';
request({
url= uri,
json:true
},(error,fbresponse,data)=>{
if(error)
{
console.error('Access Token validation request failed\n',error);
res.status(400).send(error);
}
else if(data.error)
{
console.error('Invalid Access Token\n',
'access_Token=${accessToken}',
'App_Proof=${AppSecretProof}',data.error);
res.status(400).send(data);
}
else
{
admin.auth().createCustomToken(data.id)
.then(CustomToken => res.status(200).send(CustomToken))
.catch(error => {
console.error('Create Custom Token Failed.',error);
res.status(400).send(error);
})
}
})
})
After using command-firebase deploy I got this
> G:\New folder\firebase_functions>firebase deploy
=== Deploying to 'eatitv2-8aa15'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint G:\New folder\firebase_functions\functions
> eslint .
G:\New folder\firebase_functions\functions\index.js
19:9 error Parsing error: Shorthand property assignments are valid only in destructuring patterns
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Maaz Farooq\AppData\Roaming\npm-cache\_logs\2020-07-18T16_58_24_083Z-debug.log
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
at notFoundError (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
at ChildProcess.cp.emit (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) {
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
path: 'npm --prefix "%RESOURCE_DIR%" run lint',
spawnargs: []
}
Error: functions predeploy error: Command terminated with non-zero exit code1
I see many answers on stack overflow as well as on github, but nothing proceed. i have tried my best to solve it by myown also get help from online community but now posting this to all of you.
The output shows that ESLint is giving you this error message on line 19 of index.js:
19:9 error Parsing error: Shorthand property assignments are valid only in destructuring patterns
Line 19 is url= uri below:
request({
url= uri,
json:true
},(error,fbresponse,data)=>{
If you want to give values to properties in a JavaScript objects, you have to use : instead of =, just like you did with json:true.
request({
url: uri,
json:true
},(error,fbresponse,data)=>{
I try to pass a custom flag from npm script to my webpack config but it results in following error. The logs
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
ERROR in Entry module not found: Error: Can't resolve '--no-dist' in 'C:\Users\user\gitroot\MyProject\sharepoint'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-project#4.0.0 dev: `webpack --mode development -- --no-dist`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the my-project#4.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
package.json
...
"scripts": {
"dev": "webpack --mode development -- --no-dist",
"dev:dist": "webpack --mode development",
"build": "webpack --mode production"
},
...
webpack.config.js
let username = process.env.USERNAME;
if (process.env.npm_config_user !== undefined && process.env.npm_config_user !== "") {
username = process.env.npm_config_user;
}
console.log("username", username);
console.log("process.argv.slice(2)", process.argv.slice(2));
const no_dist = process.argv.slice(2).indexOf("--no-dist") > -1;
console.log("no_dist", no_dist);
Tests
npm run dev:dist
This works without errors, it gets bundled and distributed without problems. Gives the following output:
username user
process.argv.slice(2) [ '--mode', 'development' ]
no_dist false
npm run dev:dist --user test
Also works and gives the following output:
username test
process.argv.slice(2) [ '--mode', 'development' ]
no_dist false
npm run dev
Here it gets interesting, I try to run the dev script which has a --no-dist flag. Output:
username user
process.argv.slice(2) [ '--mode', 'development', '--', '--no-dist' ]
no_dist true
As you can see, no_dist boolean is set to true, which is the wanted behaviour. But I get the following error:
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
npm run dev --user test
Same behaviour as test 3. The arguments are passed to the webpack.config.js but result in the same error.
username test
process.argv.slice(2) [ '--mode', 'development', '--', '--no-dist' ]
no_dist true
Am I missing something here?
As #squgeim mentioned, webpack does not support flags and environment variables should be used. This pointed me in the right direction: Environment variables
I changed my package.json and webpack.config.js file like this:
package.json
"scripts": {
"dev": "webpack --mode development --env.dist=false",
"dev:dist": "webpack --mode development",
"build": "webpack --mode production"
},
--env.dist=false adds dist to the environment variables.
webpack.config.js
There is one change that you will have to make to your webpack config. Typically, module.exports points to the configuration object. To use the env variable, you must convert module.exports to a function.
module.exports = env => {
const no_dist = (env && env.dist === "false");
return {
//webpack configuration
}
This seems to be the correct way to do it. Thanks again #squgeim to point me in the right direction!
I just got the same error yesturday,and i found out in my case it is due to the ES6 syntax error.I used module.export instead of module.exports in webpack.config.js.
I don't think webpack supports custom cli flags in it's configurations.
The idiomatic approach is to use environment variables to pass custom arguments to your configurations.
"dev:dist": "DIST=true webpack --mode development"
And access it like:
if (process.env.DIST === 'true') {
}
I have a following project structure:
install.js:
var path = require('path'),
exec = require('child_process').exec;
exec('npm install', {cwd: path.join(__dirname, './some_modules')});
package.json:
"scripts": {
"install": "node install.js"
},
"dependencies": {
"gulp": "3.8.10"
},
And have some dependencies in some_modules/package.json.
In case installation locally we get the expected result:
But in case installation globally (with -g parameter) we have following broken structure:
Question: How to get rid of the influence -g parameter for install.js -> exec('npm install') ?
Try it here: https://github.com/MishaMykhalyuk/npm-i-with-g-and-hooks (npm install -g git+https://github.com/MishaMykhalyuk/npm-i-with-g-and-hooks.git).