How to use heic2any in Next.js client side? - reactjs

Have following code:
import convert from 'heic2any'
try {
convertedImage = await convert({ blob: propsAndFile?.file })
} catch (error) {
console.error(error)
}
But got this error, though they promise it will run on client side: https://www.npmjs.com/package/heic2any
info - Collecting page data ..node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
ReferenceError: window is not defined
at /Users/janoskukoda/Workspace/tikex/portal/team/node_modules/heic2any/dist/heic2any.js:23:1
at /Users/janoskukoda/Workspace/tikex/portal/team/node_modules/heic2any/dist/heic2any.js:11:26
at Object.<anonymous> (/Users/janoskukoda/Workspace/tikex/portal/team/node_modules/heic2any/dist/heic2any.js:20:2)
at Module._compile (node:internal/modules/cjs/loader:1205:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
at Module.load (node:internal/modules/cjs/loader:1068:32)
at Module._load (node:internal/modules/cjs/loader:909:12)
at Module.require (node:internal/modules/cjs/loader:1092:19)
at require (node:internal/modules/cjs/helpers:103:18)
at 2233 (/Users/janoskukoda/Workspace/tikex/portal/team/.next/server/pages/_app.js:176:18) {
type: 'ReferenceError'
}
Node.js v19.1.0

Related

When I goto start up my discord bot, I get the error token is not defined

I've tried multiple fixes and I am unable to figure out what is wrong send help...
The bot at the moment is supposed to run simple commands and hopefully sometime in the near future be an application bot
Index.js
const { Client, Collection } = require("discord.js");
const client = new Client({
intents: 32767,
});
module.exports = client;
// Global Variables
client.commands = new Collection();
client.slashCommands = new Collection();
client.config = require("./config.json");
// Initializing the project
require("./handler")(client);
client.login(client.config.token);
config.json
{
"token": "My discord bot token",
"prefix": "!",
}
error
C:\Users\Hello\djs-base-handler\index.js:16
client.login(token);
^
ReferenceError: token is not defined
at Object.<anonymous> (C:\Users\Hello\djs-base-handler\index.js:16:14)
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)
at node:internal/main/run_main_module:17:47
This is not how you get your token from your json, try this instead :
//assuming the file is on the root of your project, else put the full path
const { token } = require('./config.json')
//...
client.login(token)

Invalid bitfield flag or number

I am trying to make a discord bot but when I did some code and ran it this error pops up:
index.js
const discord = require('discord.js')
const { token } = require('./config.json')
const Client = new discord.Client({
intents: [discord.Intents.FLAGS.GUILDS, discord.Intents.FLAGS.GUILD_MEMBERS, discord.Intents.FLAGS.GUILD_BANS, discord.Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, discord.Intents.FLAGS.GUILD_INTEGRATIONS, discord.Intents.FLAGS.GUILD_WEBHOOKS, discord.Intents.FLAGS.GUILD_INVITES, discord.Intents.FLAGS.GUILD_VOICE_STATES, discord.Intents.FLAGS.GUILD_PRESENCES, discord.Intents.FLAGS.GUILD_MESSAGES, discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS, discord.Intents.FLAGS.GUILD_MESSAGE_TYPING, discord.Intents.FLAGS.DIRECT_MESSAGES, discord.Intents.FLAGS.DIRECT_MESSAGE_REACTION, discord.Intents.FLAGS.DIRECT_MESSAGE_TYPING]
})
Client.on('ready', () => {
console.log(`${Client.user.tag} is online!`)
})
Client.login(token)
config.json
{
"token": "my_token"
}
When I run the code I get this error
C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:152
throw new RangeError('BITFIELD_INVALID', bit);
^
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
at Function.resolve (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:152:11)
at C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:147:54
at Array.map (<anonymous>)
at Function.resolve (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:147:40)
at Client._validateOptions (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\client\Client.js:546:33)
at new Client (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\client\Client.js:73:10)
at Object.<anonymous> (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\index.js:3:16)
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) {
[Symbol(code)]: 'BITFIELD_INVALID'
}
How can I fix this issue?
I am using Discord.js V13
Node.js 16.7
Small Typo: DIRECT_MESSAGE_REACTION -> DIRECT_MESSAGE_REACTIONS on line 4 of index.js.
That's probably why node is freaking out about an invalid bitfield flag; discord.Intents.FLAGS.DIRECT_MESSAGE_REACTION is undefined (a.k.a it doesn't exist).

"Discord is not refined"

I am very new to coding and I tried coding my own discord bot and I got the "discord is not refined" in command prompt. I am currently just trying to turn on the bot to see if it works, anyways here is the code
const Discord = require("discord.js");
const client = new Discord.Client();
client.once('ready'), () => {
console.log('HelloMyFriend is online!');
};
client.login('<token>');
stack trace
events.js:131
throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
←[90m at checkListener (events.js:131:11)←[39m
←[90m at Client.once (events.js:496:3)←[39m
at Object.<anonymous> (C:\Users\jamie\Desktop\DiscordBot\main.js:7:8)
←[90m at Module._compile (internal/modules/cjs/loader.js:1068:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:933:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:774:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
code: ←[32m'ERR_INVALID_ARG_TYPE'←[39m
}
The first event on ready is wrong. You shouldn't be closing the parentheses after the 'ready'.
You should also use on instead of once.
client.on('ready', () => {
console.log('HelloMyFriend is online!');
});
To overcome this error you can replace your ready event with the following:
client.once('ready', () => {
console.log('HelloMyFriend is online!');
});
I would also recommend an .env file to protect the token of the bot. Once it becomes public, it should be generated again in the Discord Developer Portal to prevent possible hijacking of the bot.

Protractor- getText() showing error in async/await

Failing to perform getText() and use in expect condition using async/await. Following is the it block
it('Apply permission to a folder', async () => {
await docsHomePage.clickProject();
await projectsPage.projectCreateNewFolderAndSelect("AutoProject");
await projectsPage.uploadFile('Aug2017.pdf');
//uploadMessageElement = await projectsPage.getFileUploadSuccessMessage();
let uploadMessageText = element(by.id('projects-upload-success-new'));
expect(await uploadMessageText.getText()).toEqual('1 new Document created sucessfully');
await projectsPage.clickFileUploadSuccessCloseButton();
});
Getting the following error:
2) Non Angular CLM Page Apply permission to a folder
Message:
Failed: script timeout
(Session info: chrome=79.0.3945.117)
Stack:
ScriptTimeoutError: script timeout
(Session info: chrome=79.0.3945.117)
at Object.throwDecodedError
(C:\Users\sagar.ladwa\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium- webdriver\lib\error.js:514:15)
at parseHttpResponse (C:\Users\sagar.ladwa\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:519:13)
at doSend.then.response (C:\Users\sagar.ladwa\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:68:7)Error
at ElementArrayFinder.applyAction_ (C:\Users\sagar.ladwa\AppData\Roaming\npm\node_modules\protractor\built\element.js:459:27)
at ElementArrayFinder.(anonymous function).args [as getText] (C:\Users\sagar.ladwa\AppData\Roaming\npm\node_modules\protractor\built\element.js:91:29)
at ElementFinder.(anonymous function).args [as getText] (C:\Users\sagar.ladwa\AppData\Roaming\npm\node_modules\protractor\built\element.js:831:22)
at UserContext.it (C:\Users\sagar.ladwa\Downloads\protractor-initial-project-master\protractor-initial-project-master\specs\user-groups-permission.js:57:45)
at process._tickCallback (internal/process/next_tick.js:68:7)
From asynchronous test:
Error
at Suite.describe (C:\Users\sagar.ladwa\Downloads\protractor-initial-project-master\protractor-initial-project-master\specs\user-groups-permission.js:49:5)
at Object.<anonymous> (C:\Users\sagar.ladwa\Downloads\protractor-initial-project-master\protractor-initial-project-master\specs\user-groups-permission.js:7:1)
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)
Getting similar issue when we tried to create a page-object.
It's your console.log which is causing the issue. If you want to print the text you will need to await uploadMessageText.getText() there also.
This will likely be easier for you
let uploadMessageText = await element(by.id('projects-upload-success-new')).getText()
console.log('-----------------------------------'+uploadMessageText);
expect(uploadMessageText).toEqual('1 new Document created sucessfully');

Importing AngularJS 1.6 into Angular-Universal Project

We have a hybrid Angular6 and AngularJS 1.6 project which we are currently migrating. In this process, we also want to introduce Server Side Rendering (SSR).
The problem is, that the SSR is running in a node environment, so running the SSR/prerendering gets the following error:
npm-run ts-node ./prerender.ts
[..]/node_modules/angular/index.js:2
**module.exports = angular;**
**ReferenceError: angular is not defined**
at Object.<anonymous> ([..]/node_modules/angular/index.js:2:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.angular ([..]/dist/server/webpack:/external "angular":1:1)
at _webpack_require_
([..]/dist/server/webpack:/webpack/bootstrap:19:1)
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import {renderModuleFactory} from '#angular/platform-server';
import {writeFileSync} from 'fs';
const globalAny:any = global;
const Window = require('window');
let window = new Window();
globalAny.window = window;
globalAny.document = window.document;
const {AppServerModuleNgFactory} = require('./dist/server/main');
renderModuleFactory(AppServerModuleNgFactory, {
document: '<app-root></app-root>',
url: '/'
})
.then(html => {
console.log('Pre-rendering successful, saving prerender.html');
writeFileSync('./prerender.html', html);
})
.catch(error => {
console.error('Error occurred:', error);
});
The Project is based on the universal-starter repo: https://github.com/angular/universal-starter
Any suggestions what's going on here?

Resources