Unhandled Runtime ErrorError: Element type is invalid. Received a promise that resolves to: undefin
Answered
dperolio posted this in #help-forum
dperolioOP
I'm getting this error message, but I'm confused as to why?
For my component, I have:
For my page.tsx, I have:
For my component, I have:
'use client';
import { getRandomString } from '#utils';
import api from '#api';
export default function Test () {
async function createNewUser () {
await api.user.add(`bob${getRandomString(10)}@aol.com`, 'testtest', { firstName: 'Bob' });
}
return (
<button onClick={createNewUser}>
Hello
</button>
);
}For my page.tsx, I have:
import { Body, Test } from '#components';
export default function Login () {
return (
<Body>
<Test />
</Body>
);
}36 Replies
dperolioOP
Bump.
dperolioOP
dperolioOP
No one knows?
dperolioOP
Bump.
dperolioOP
@Sun bear Get AI to solve this please, it seems very basic.
I'm not using React.lazy though. Why is it an async component?
Sun bear
It's a component that is asynchrounous I guess
dperolioOP
Can I not have async functions in a component without using React.lazy? That shouldn't be the case.
Sun bear
I don't know that. Hmm, if that error came up after updating the code based on what Gpt said I'd suggest reverting the code back to how you had.
dperolioOP
Seems to be working now. It's been weird.
Sun bear
Is it doing what you wanted it to do at least ?
dperolioOP
Yeah, it seems to be. It always has been, but Next has been showing the red error popup sometimes.
Sun bear
Could come up from some async components or somethin if you're using SSR.
If the content loads first on the server or on the client and if it's not supposed to then it could cause errors like that I think but not sure if that's what's going on. If that's the case it may be a bit difficult to reproduce them but if you can get someone that knows programming well to look over your codebase they might be able to spot what can cause that.
Sun bear
It could also be some sort of a bug or glitch in Next js.
Answer
dperolioOP
Alright, thanks. I'm not seeing the error anymore, so I'm going to chalk it up to a glitch for now.
Want to help me coming up with a routing system better than doing
${lang}/blah for every link?Basically, I use this constant for my route paths.
/**
* The various route locations used throughout the app.
*/
export const Routes = {
OUTREACH_HISTORY: '/outreach/history',
OUTREACH_CREATE: '/outreach/create',
HOME: '/',
DASHBOARD: '/dashboard',
FORGOT_PASSWORD: '/forgot-password',
LOGIN: '/login',
PROFILE: '/profile',
REGISTER: '/register',
OUTREACH: (outreachId: snowflake) => outreachId ? `/outreach/${outreachId}` : '/outreach',
OUTREACH_JOIN: (registrationCode?: string) => `/outreach/join/${registrationCode ? `?code=${registrationCode}` : ''}`,
OUTREACH_DRAFT: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}draft`,
OUTREACH_OPEN: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}open`,
OUTREACH_TEAMS: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}teams`,
OUTREACH_PENDING: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}pending`,
OUTREACH_ACTIVE: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}active`,
OUTREACH_STANDBY: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}standby`,
OUTREACH_COMPLETE: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}complete`,
...
} as const;Trying to think how it could be done sort of like the
getDictionary, where you would have like const Routes = getRoutes(lang) and then just use Routes.HOME or whatever like normal.Ah, nice. ChatGPT came through. lol
@dperolio Basically, I use this constant for my route paths.
ts
/**
* The various route locations used throughout the app.
*/
export const Routes = {
OUTREACH_HISTORY: '/outreach/history',
OUTREACH_CREATE: '/outreach/create',
HOME: '/',
DASHBOARD: '/dashboard',
FORGOT_PASSWORD: '/forgot-password',
LOGIN: '/login',
PROFILE: '/profile',
REGISTER: '/register',
OUTREACH: (outreachId: snowflake) => outreachId ? `/outreach/${outreachId}` : '/outreach',
OUTREACH_JOIN: (registrationCode?: string) => `/outreach/join/${registrationCode ? `?code=${registrationCode}` : ''}`,
OUTREACH_DRAFT: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}draft`,
OUTREACH_OPEN: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}open`,
OUTREACH_TEAMS: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}teams`,
OUTREACH_PENDING: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}pending`,
OUTREACH_ACTIVE: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}active`,
OUTREACH_STANDBY: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}standby`,
OUTREACH_COMPLETE: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}complete`,
...
} as const;
Sun bear
I would love to but I don't think that I'm the right person to ask for help when it comes to programming at the moment. I think it's better to wait for someone else to jump in to better assist you.
@dperolio Ah, nice. ChatGPT came through. lol
Sun bear
Awesome! If you want me to prompt gpt 4 for you just let me know, that I can do.
dperolioOP
Ah, nice, I'm using 3.5.
You could ask it if it can improve this:
type Routes = {
[key: string]: string | ((param?: string) => string);
};
function getRoutes(lang: string): Routes {
const prefix = lang === 'en' ? '' : `/${lang}`;
return {
OUTREACH_HISTORY: `${prefix}/outreach/history`,
OUTREACH_CREATE: `${prefix}/outreach/create`,
HOME: prefix,
DASHBOARD: `${prefix}/dashboard`,
FORGOT_PASSWORD: `${prefix}/forgot-password`,
LOGIN: `${prefix}/login`,
PROFILE: `${prefix}/profile`,
REGISTER: `${prefix}/register`,
OUTREACH: (outreachId: snowflake) => outreachId ? `${prefix}/outreach/${outreachId}` : `${prefix}/outreach`,
OUTREACH_JOIN: (registrationCode?: string) => `${prefix}/outreach/join${registrationCode ? `?code=${registrationCode}` : ''}`,
OUTREACH_DRAFT: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}draft`,
OUTREACH_OPEN: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}open`,
OUTREACH_TEAMS: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}teams`,
OUTREACH_PENDING: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}pending`,
OUTREACH_ACTIVE: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}active`,
OUTREACH_STANDBY: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}standby`,
OUTREACH_COMPLETE: (outreachId: snowflake) => `${Routes.OUTREACH(outreachId)}complete`,
// Add other routes as needed
};
}
// Usage:
const lang = 'es'; // or 'en' or any other supported language
const Routes = getRoutes(lang);
// Now you can use Routes.HOME, Routes.DASHBOARD, etc. with the specified language prefix@dperolio Ah, nice, I'm using 3.5.
Sun bear
I think you should try this instead, it's free and closer to 4 😠https://claude.ai/login?returnTo=%2F
dperolioOP
I can't think of anything to improve it, but maybe there's a way.
@dperolio Thanks.
Sun bear
You're welcome. Also here's what GPT 4 said https://chat.openai.com/share/5304f33a-9260-47e6-8454-6da7c858b8df
dperolioOP
rip my developer career and lifestyle
dperolioOP
Signed up for GPT 4 instead.
Damn, you're limited to 40 messages every 3 hours?
Or is that only for DALL-E?
@dperolio Damn, you're limited to 40 messages every 3 hours?
Sun bear
It looks like it.
And from what I understand when you generate images it may consume more than 1 prompt so you may reach the limit faster when doing so. Same if you are using custom GPTs from their GPTs store but not 100% that's how it works, it's just what I've heard from some folks in their discord server.
And from what I understand when you generate images it may consume more than 1 prompt so you may reach the limit faster when doing so. Same if you are using custom GPTs from their GPTs store but not 100% that's how it works, it's just what I've heard from some folks in their discord server.
dperolioOP
Do you ever hit the limit?
Sun bear
Pretty rarely.
I usually hit it when I play around with image generation but when using it for helping me with code I rarely hit it because it usually takes time for me to test things out, think about things and such.