Can you help me to solve this error about json? - javascript

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)=>{

Related

TypeError: Cannot read property 'length' of undefined - While deploying using hardhat

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.

Inserting uuid into sqlite Database in node doesnt work

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 building a Slack Bot but getting an error

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

Next JS build failed on shared hosting

When I run "npm run build" on my shared hosting server it throws an error: spawn ENOMEM
It runs fine on my localhost and was running fine on the hosting server for a couple of weeks until yesterday.
> mysite#1.0.0 build /home/user123/public_html
> next build
Creating an optimized production build ...internal/child_process.js:366
throw errnoException(err, 'spawn');
^
Error: spawn ENOMEM
at ChildProcess.spawn (internal/child_process.js:366:11)
at spawn (child_process.js:551:9)
at Object.fork (child_process.js:113:10)
at ChildProcessWorker.initialize (/home/user123/public_html/node_modules/jest-worker/build/workers/ChildProcessWorker.js:137:44)
at new ChildProcessWorker (/home/user123/public_html/node_modules/jest-worker/build/workers/ChildProcessWorker.js:127:10)
at WorkerPool.createWorker (/home/user123/public_html/node_modules/jest-worker/build/WorkerPool.js:44:12)
at new BaseWorkerPool (/home/user123/public_html/node_modules/jest-worker/build/base/BaseWorkerPool.js:82:27)
at new WorkerPool (/home/user123/public_html/node_modules/jest-worker/build/WorkerPool.js:30:1)
at new JestWorker (/home/user123/public_html/node_modules/jest-worker/build/index.js:131:26)
at TaskRunner.run (/home/user123/public_html/node_modules/next/dist/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js:3:166)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mysite#1.0.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mysite#1.0.0 build 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! /home/user123/.npm/_logs/2019-09-24T19_27_41_300Z-debug.log
and this is the debug log
0 info it worked if it ends with ok
1 verbose cli [ '/home/user123/node/bin/node',
1 verbose cli '/home/user123/node/bin/npm',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm#6.11.3
3 info using node#v10.16.3
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle mysite#1.0.0~prebuild: mysite#1.0.0
6 info lifecycle mysite#1.0.0~build: mysite#1.0.0
7 verbose lifecycle mysite#1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle mysite#1.0.0~build: PATH: /home/user123/node/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/user123/public_html/node_modules/.bin:/home/user123/node/bin:/home/user123/node/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/cpanel/composer/bin:/opt/puppetlabs/bin:/opt/dell/srvadmin/bin:/usr/local/bin:/usr/X11R6/bin:/home/user123/.local/bin:/home/user123/bin
9 verbose lifecycle mysite#1.0.0~build: CWD: /home/user123/public_html
10 silly lifecycle mysite#1.0.0~build: Args: [ '-c', 'next build' ]
11 silly lifecycle mysite#1.0.0~build: Returned: code: 1 signal: null
12 info lifecycle mysite#1.0.0~build: Failed to exec build script
13 verbose stack Error: mysite#1.0.0 build: `next build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/home/user123/node/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (/home/user123/node/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid mysite#1.0.0
15 verbose cwd /home/user123/public_html
16 verbose Linux 2.6.32-954.3.5.lve1.4.66.el6.x86_64
17 verbose argv "/home/user123/node/bin/node" "/home/user123/node/bin/npm" "run" "build"
18 verbose node v10.16.3
19 verbose npm v6.11.3
20 error code ELIFECYCLE
21 error errno 1
22 error mysite#1.0.0 build: `next build`
22 error Exit status 1
23 error Failed at the mysite#1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
I am using express and next js .
This is my server.js
const express = require( 'express' );
const next = require( 'next' );
// Import middleware.
const routes = require( './routes' );
// Setup app.
const app = next( { dev: 'production' !== process.env.NODE_ENV } );
const handle = app.getRequestHandler();
const handler = routes.getRequestHandler( app );
app.prepare()
.then( () => {
// Create server.
const server = express();
// Use our handler for requests.
server.use( handler );
// Don't remove. Important for the server to work. Default route.
server.get( '*', ( req, res ) => {
return handle( req, res );
} );
// Get current port.
const port = process.env.PORT || 8080;
// Error check.
server.listen( port, err => {
if ( err ) {
throw err;
}
// Where we starting, yo!
console.log( `> Ready on port ${port}...` );
} );
} );
I've looked into swap space / memory and it seems like it's fine
total used free shared buffers cached
Mem: 31906 31330 575 21 2982 16900
-/+ buffers/cache: 11447 20459
Swap: 8191 0 8191
I've also tried doing NODE_OPTIONS=--max-old-space-size=2048 npm run build and still doesn't work
Anyone have any idea what's wrong?
It seems like it is related to the NextJs version 9 as it consumes too much memory for building the app. You can find discussion about that issue here: https://github.com/zeit/next.js/issues/7929
Version 8 seems to not have that issue, so if downgrading is your option, you can do that for now.
Additionally, if that still doesn't help, disabling minimization in next.config.js will reduce memory usage:
module.exports = {
webpack: (config, options) => {
config.optimization.minimize = false;
return config
}
}
If you do not want to exclude minimization, I found out that with version 8 you can build your app locally and move already built folder to your shared hosting without having to run "next build" on shared hosting again. I couldn't do that with version 9.
Update: Tested on NextJs version 8.1

Why can't I deploy this code to firebase functions? I don't understand the error

I'm new to firebase functions - obviously - and I'm trying to test to see if an email in that specific path of the database when created is being used by an account if it isn't being used then change that database value accordingly. Here's the code:
exports.checkEmail = functions.database.ref('/checkEmailExistance')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const email = snapshot.val();
console.log('Email:', email, context.params.pushId);
admin.auth().getUserByEmail(email)
.then(snapshot => {
const data = snapshot.toJSON()
return admin.database().ref('checkEmailExistance').child(email).set("Nope")
})
});
and the error is:
ERROR: /Users/nathan/Documents/FirebaseFunctionsClipify/functions/src/index.ts:41:7 - Promises must be handled appropriately
ERROR: /Users/nathan/Documents/FirebaseFunctionsClipify/functions/src/index.ts:42:13 - Shadowed name: 'snapshot'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions# lint: `tslint --project tsconfig.json`
npm ERR! Exit status 2
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! /Users/nathan/.npm/_logs/2019-04-25T16_21_29_696Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
UPDATE:
I changed the code so the errors shouldn't be produced again, but still got the same error:
exports.checkEmail = functions.database.ref('/checkEmailExistance')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const email = snapshot.val();
console.log('Email:', email, context.params.pushId);
return admin.auth().getUserByEmail(email)
.then(snap => {
const data = snap.toJSON()
return admin.database().ref('checkEmailExistance').child(email).set("Nope")
})
});
The second error is telling you that you redefined an existing variable called snapshot. Note that snapshot is defined by at the top level of your function callback, then again in the then callback. The second instance is "shadowing" the first, which is a potential error in your code. Just name the second variable something different.
The first lint error is telling you that you have an unhandled promise in your code. You can fix this by returning the promise from admin.auth().getUserByEmail().then(...):
return admin.auth().getUserByEmail(email)
.then(snap => {
const data = snap.toJSON()
return admin.database().ref('checkEmailExistance').child(email).set("Nope")
})

Categories

Resources