Importing AngularJS 1.6 into Angular-Universal Project - angularjs

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?

Related

How to use heic2any in Next.js client side?

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

Discord.js error '.addChoice' is not a function

i have some Problems with my Code that somehow none of my friends have ...
Some Code to see:
module.exports = {
data: new SlashCommandBuilder()
.setName('equipment')
.setDescription('Gives you Information about specific Equipments')
.addStringOption(option =>
option.setName('type')
.setDescription('Specify the Equipment')
.setRequired(true)
.addChoice('Flashlight', 'flashlight')
),
...
The Code is Cut here because its not necesery for it above to work.
My Error Code:
PS C:\Users\enric\Desktop\Ghosty Phasmo Help> node .
C:\Users\enric\Desktop\Ghosty Phasmo Help\commands\phasmo\equipment.js:15
.addChoice('Flashlight', 'flashlight')
^
TypeError: option.setName(...).setDescription(...).setRequired(...).addChoice is not a function
at C:\Users\enric\Desktop\Ghosty Phasmo Help\commands\phasmo\equipment.js:15:18
at MixedClass._sharedAddOptionMethod (C:\Users\enric\Desktop\Ghosty Phasmo Help\node_modules\#discordjs\builders\dist\index.js:1334:50)
at MixedClass.addStringOption (C:\Users\enric\Desktop\Ghosty Phasmo Help\node_modules\#discordjs\builders\dist\index.js:1323:17)
at Object.<anonymous> (C:\Users\enric\Desktop\Ghosty Phasmo Help\commands\phasmo\equipment.js:11:7)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157: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:102:18)
Somehow my Discord.js thinks that im using a Function. I copied the Code from other friends where this completely work. but somehow the same Error message appears.
.addChoice() is outdated. Now, there is only .addChoices() (with an s)
.addStringOption(option =>
option.setName('type')
.setDescription('Specify the Equipment')
.setRequired(true)
.addChoices({
name: 'Flashlight',
value: 'flashlight'
})
)

Npm run build not working NEXTJS says TM undefined

I am trying to run npm run build on my NextJs project. The terminal says:
info - Loaded env from /mnt/c/Users/chloe/case4/2022-ca400-TEMPLATE/src/sage-project/.env.local
error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
> Build error occurred
ReferenceError: withTM is not defined
at Object.<anonymous> (/mnt/c/Users/chloe/case4/2022-ca400-TEMPLATE/src/sage-project/next.config.js:13: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 ModuleWrap.<anonymous> (node:internal/modules/esm/translators:190:29)
at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
and my next.config.js file looks like this:
/** #type {import('next').NextConfig} */
const withTM = require("next-transpile-modules")([
"#fullcalendar/common",
"#babel/preset-react",
"#fullcalendar/common",
"#fullcalendar/daygrid",
"#fullcalendar/interaction",
"#fullcalendar/react",
"#fullcalendar/timegrid",
]);
module.exports = withTM({
reactStrictMode: true
});
It says withTM isn't defined, but it is with const? Where am I going wrong?

Why do I keep getting this error when I try to get my discord bot online

I tried making a discord bot and I did the first steps and the command prompt when I type node . shows this:
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\giann\Desktop\BWKS\node_modules\discord.js\src\client\Client.js:548:13)
at new Client (C:\Users\giann\Desktop\BWKS\node_modules\discord.js\src\client\Client.js:76:10)
at Object. (C:\Users\giann\Desktop\BWKS\main.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155: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:77:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
I tried almomst everything but this error is coming up all the time.
the code:
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready')
});
client.login('the token');
Discord needs to know what intents you want to use. So to fix your code, use:
const client = new Discord.Client({ intents: [<ARRAY WITH ALL INTENTS>] });
client.once('ready', () => {
console.log('Ready')
});
client.login('the token');
You can add intents in the array by using a string "GUILDS" or use the property Intents.FLAGS.GUILDS
A list of all intents can be found here: https://discord.js.org/#/docs/discord.js/stable/class/Intents

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)

Resources