Deploying nuxt edge to firebase with function get an error - javascript

I try to deploy nuxt project using the latest version of Nuxt which is nuxt-edge to firebase. This is my function code.
const { Nuxt } = require('nuxt-edge')
const express = require('express')
const functions = require('firebase-functions')
const app = express()
const config = {
dev: false,
buildDir: 'nuxt',
build: {
extractCSS: true,
cache: false,
parallel: true,
publicPath: '/assets/'
}
}
const nuxt = new Nuxt(config)
const handleRequest = (req, res) => {
return new Promise((resolve, reject) => {
nuxt.render(req, res, promise => {
promise.then(resolve).catch(reject)
})
})
}
app.use(handleRequest)
exports.jefrydcossr = functions.https.onRequest(app)
It successfully run locally with firebase serve --only hosting,function command. But when I deployed it online and I open the hosting url, I got server error 500.
After I looked at the error log, I got error like this
2018-06-14T12:43:26.094Z D jefrydcossr: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error: only one instance of babel-polyfill is allowed
at Object.<anonymous> (/user_code/node_modules/nuxt-edge/node_modules/babel-polyfill/lib/index.js:10:9)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/node_modules/nuxt-edge/dist/nuxt-legacy.js:50:1)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
2018-06-14T12:43:26.206Z E jefrydcossr: undefined
2018-06-14T12:51:04.440Z N jefrydcossr: undefined
2018-06-14T12:53:28.052Z N jefrydcossr: undefined
The repository of this project here https://github.com/jefrydco/jefrydco-id

Related

Discord.js & Canvacord: Error: libuuid.so.1: cannot open shared object file: No such file or directory

After I added level.js file in my commands folder and ran the bot, it showed up the error:
node:internal/modules/cjs/loader:1183
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: libuuid.so.1: cannot open shared object file: No such file or directory
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object.<anonymous> (/home/runner/UnfortunateDistortedEngine/node_modules/canvas/lib/bindings.js:3:18)
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 Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object.<anonymous> (/home/runner/UnfortunateDistortedEngine/node_modules/canvas/lib/canvas.js:9:18)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) {
code: 'ERR_DLOPEN_FAILED'
}
The code of level.js file:
const { client, CommandInteraction, MessageEmbed } = require("discord.js");
const db = require('quick.db')
const canvacord = require("canvacord");
const Levels = require('discord-xp')
module.exports = {
name: "level",
description: "Displays the user's level and XP.",
type: 'CHAT_INPUT',
options: [
{
name: "member",
type: "USER",
description: "Specify a user.",
required: false
}
],
run: async (client, interaction, args) => {
let user1 = message.author;
const Blacklisted = db.fetch(`blacklistedUsers_${user1.id}`)
if (Blacklisted === true) return;
let target = await interaction.options.getUser('member')
let mentionedMember = target || interaction.user;
const user = await Levels.fetch(mentionedMember.id, interaction.guild.id, true)
const rank = new canvacord.Rank()
.setAvatar(mentionedMember.displayAvatarURL({ format: 'png', size: 512 }))
.setCurrentXP(mentionedMember.xp || 0)
.setRequiredXP(Levels.xpFor(user.level + 1) || Levels.xpFor(1))
.setRank(user.position)
.setLevel(user.level)
.setStatus(mentionedMember.presence.status)
.setBackground("IMAGE", "https://i.pinimg.com/originals/22/90/0f/22900f16a05211e2562828b6b3fe86b7.jpg")
.setProgressBar("#FFFFFF")
.setUsername(mentionedMember.username)
.setDiscriminator(mentionedMember.discriminator);
rank.build()
.then(data => {
const attachment = new MessageAttachment(data, "RankCard.png");
interaction.followUp({
files: [attachment]
})
});
}
}
There already was an issue opened on GitHub, but the opener didn't state any solution, just said "Solved". This is related to the Canvacord package that uses canvas.
You need libuuid which is a dependency of node-canvas which in return is a dev dependency of canvacord, it is usually preinstalled in many linux systems although you can use
apt-get install libuuid1
to install it, this should solve the issue, please note that you might have to use Nix if you are using a host such as repl.it in which you do not have root access.
Well, if you're using replit it's showing that error... So, I suggest you to change your replit.nix with the given nix below it would definitely fixed your issue!
{ pkgs }: {
deps = [
pkgs.nodejs-16_x
pkgs.libuuid
];
env = {
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [pkgs.libuuid];
};
}

No such file directory when compile solidity with node fs library

I'm trying to compile solidity using node compile.js. I have attached the code below:
Here is my simple demo structure:
contracts
node_modules
compile.js
Incrementer.sol
package.json
package-lock.json
Here is compile.js
const fs = require('fs');
const solc = require('solc');
const path = require('path');
// Get Path and Load Contract
const inboxPath = path.resolve(__dirname, 'Incrementer.sol');
console.log(inboxPath) // This one provide directory to read (/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
const source = fs.readFileSync(inboxPath, 'utf8'); // still getting stuck on this
// Compile Contract
const input = {
language: 'Solidity',
sources: {
'Incrementer.sol': {
content: source,
},
},
settings: {
outputSelection: {
'*': {
'*': ['*'],
},
},
},
};
const tempFile = JSON.parse(solc.compile(JSON.stringify(input)));
const contractFile = tempFile.contracts['Incrementer.sol']['Incrementer'];
// Export Contract Data
module.exports = contractFile;
Incrementer.sol:
pragma solidity ^0.8.0;
contract Incrementer {
uint256 public number;
constructor(uint256 _initialNumber) {
number = _initialNumber;
}
function increment(uint256 _value) public {
number = number + _value;
}
function reset() public {
number = 0;
}
}
Packages.json
{
"dependencies": {
"solc": "^0.8.0",
"web3": "^1.5.3"
}
}
I have been tried many different approach but still getting errors:
internal/fs/utils.js:314
throw err;
^
Error: ENOENT: no such file or directory, open
'/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
at Object.openSync (fs.js:498:3)
at Object.readFileSync (fs.js:394:35)
at Object.<anonymous> (/Users/amstriker/Desktop/Sdax/OnePlace/contracts/compile.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/steven/Desktop/Sdax/OnePlace/contracts/get.js:2:17)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
}
Any helps would be appreciated!!.
It failed because of space solidity filename( Incrementer.sol). It is working fine after i changed from Incrementer.sol to Incrementer.sol.

Implementing Puppeteer in node.js

I have my template which I want to export in pdf. The engine I am using is of PUG. I have this file in which I make a GET call to export the pdf.
But when I start my server - node index.js
I get error (shared below)
const express = require ('express');
var router = express.Router();
const puppeteer = require('puppeteer');
router.get('/export/html', (res,req) => {
res.render('template');
});
router. get('/export/pdf', (req, res) => {
(async () => {
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://localhost:3000/export/html');
// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
};
});
console.log('Dimensions:', dimensions);
await browser.close();
} catch(e) {
console.log(e);
}
})();
});
module.exports = router;
$ node index.js
E:\16pf\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:707
catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (E:\16pf\node_modules\puppeteer\lib\cjs\puppeteer\common\Target.js:19:19)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
Shahrukh#DESKTOP-CQ0JNTJ MINGW64 /e/16pf
$
I am not sure why is this error occurring. Any help is appreciated.
You may use an old Node.js version than does not support optional catch binding. See support list: https://node.green/#ES2019-misc-optional-catch-binding
Nothing more than a javascript syntax error. Edit the line 707 with Nano:
nano +707 "E:\16pf\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js"
Change:
catch {
To:
catch(err) {
vsemozhebuty's answer may be better because even after you fix said javascript errors, you may have to fix a bunch more in order to get it to work.

Unexpected identifier in async awaitCurrentBlock () while running my .js file

I am facing an issue while running my compile.js file using node compile.js .
My code:
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
'nut plug quality level uncle jeans retire guide eagle gossip cluster sudden',
'https://rinkeby.infura.io/v3/37097b2064214600912ad8a746ff433a'
);
const web3 = new Webs(provider);
const deploy = async (() => {
const accounts = await (web3.eth.Accounts());
console.log('Attempting to deploy from account', accounts[0]);
const result = await(new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({gas: '1000000', from: accounts[0]})
);
console.log('contract deployed to', result.options.address);
});
deploy();
After running : node compile.js
Error log:
/home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js:38
async awaitCurrentBlock () {
^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/edureka/sankalp_practice/inbox/node_modules/web3-provider-engine/index.js:4:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
I did my analysis and it seems that "const HDWalletProvider = require('truffle-hdwallet-provider');" is calling for function async awaitCurrentBlock () in /home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js.
So please let me know how to resolve it.
system: Ubuntu
version of node: v6.11.4
version of npm : 5.4.2
your dependency uses "async awaitCurrentBlock" that looks like node 8.* in which case you're simply using too old version of node. You want that dependency, then you have to update, but that will break your code in another way -> you're importing dependencies "async" and "await" which are reserved keywords in Node 8, so you'll have to update your syntax too

Call a helper functions anywhere in the applicaion - Node/Express

I have a controller
import request from 'request-promise'
import env from 'dotenv'
const dotenv = env.config();
/*==================================
= getCPEInfo =
==================================*/
function getCPEInfo(req, res)
{
var $cpeMac = req.body.cpeMac;
return new Promise((resolve, reject) => {
request({ uri: `${process.env.API_HOST}/vse/ext/vcpe/${$cpeMac}` })
.then((cpe) => resolve(JSON.parse(cpe).data))
.catch((error) => reject(error));
});
}
module.exports = {
getCPEInfo
};
I want to call this getCPEInfo() on my other files in my project
I tried import
import generalController from './controllers/general.js'
and call it
generalController.getCPEInfo();
I kept getting
[nodemon] restarting due to changes...
[nodemon] starting `babel-node ./index.js`
/Users/bheng/Desktop/express-app/index.js:72
router.post('/getCPEInfo/:cpeMac', generalController.getCPEInfo);
^
ReferenceError: generalController is not defined
at Object.<anonymous> (/Users/bheng/Desktop/express-app/index.js:37:36)
at Module._compile (module.js:643:30)
at loader (/Users/bheng/Desktop/express-app/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/bheng/Desktop/express-app/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at Object.<anonymous> (/Users/bheng/Desktop/express-app/node_modules/babel-cli/lib/_babel-node.js:154:22)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
[nodemon] app crashed - waiting for file changes before starting...
Can someone please give me a hint ?
import generalController from './controllers/general.js' will refer to the default export from the module, you need to refactor your controller :
import request from 'request-promise'
import env from 'dotenv'
const dotenv = env.config();
/*==================================
= getCPEInfo =
==================================*/
function getCPEInfo(req, res)
{
var $cpeMac = req.body.cpeMac;
return new Promise((resolve, reject) => {
request({ uri: `${process.env.API_HOST}/vse/ext/vcpe/${$cpeMac}` })
.then((cpe) => resolve(JSON.parse(cpe).data))
.catch((error) => reject(error));
});
}
var Mycontroller = {
getCPEInfo
};
export default MyController
Take a look here.

Categories