Import not working

"use client" import { useEffect } from 'react' import { useRouter } from 'next/navigation' import { InstantRedirect } from "@/utils/redirect.js" export default function Home() { const router = useRouter() useEffect(() => { InstantRedirect(router) }, [router]) return null } "use client"; export function setupRedirectOnClick(router, buttonIds) { buttonIds.forEach(id => { const button = document.getElementById(id); if (button) { button.addEventListener("click", () => { const path = button.getAttribute("data-path"); if (path) { router.replace(path) }; }); }; }); } export function InstantRedirect(router) { router.replace("/home") }; { "compilerOptions": { "baseUrl": ".", "paths": { "@components/": ["./src/components/"], "@styles/": ["./styles/"], "@utils/": [".src/utils/"] } } }
No description
No description
33 Replies
Jochem
Jochem2mo ago
it looks like it can't find @/utils/redirect.js where did that import come from?
CodeGrid
CodeGridOP2mo ago
From /app/page.js
Jochem
Jochem2mo ago
I mean why is it there? Is it from a package, or something you wrote yourself?
CodeGrid
CodeGridOP2mo ago
No it's the page but you get redirected to the correct page in this case /home/page.js This http://localhost:3000/ is supposed to change to http://localhost:3000/home
Jochem
Jochem2mo ago
does that import work on other pages?
CodeGrid
CodeGridOP2mo ago
Let me check I think so It doesn't show errors But even if I would remove import { InstantRedirect } from "@/utils/redirect.js" It still thinks it is there
Jochem
Jochem2mo ago
have you restarted your dev server process?
CodeGrid
CodeGridOP2mo ago
Yes Even removing npm and reinstalling it doesn't work
CodeGrid
CodeGridOP2mo ago
No description
Jochem
Jochem2mo ago
the code on the left in the trace does not match the code on the right in your editor
CodeGrid
CodeGridOP2mo ago
That's true I restarted the dev server and it stills shows this
Jochem
Jochem2mo ago
what does layout.js look like?
CodeGrid
CodeGridOP2mo ago
import "../styles/globals.css" import Logo from '../public/Logo.png' export const metadata = { title: "Personal portfolio", icons: { icon: '/favicon.ico', } }; export default function RootLayout({ children }) { return ( <html lang="en"> <head /> <body>{children}</body> </html> ); }
CodeGrid
CodeGridOP2mo ago
Also doesn't work in edge
No description
Jochem
Jochem2mo ago
I mean, it's a build error, the browser doesn't matter Can you show a bigger screenshot of the terminal window?
CodeGrid
CodeGridOP2mo ago
No description
Jochem
Jochem2mo ago
and jsconfig.json?
CodeGrid
CodeGridOP2mo ago
No description
Jochem
Jochem2mo ago
your import should be import { InstantRedirect } from "@utils/redirect.js" where did the import { InstantRedirect } from "@/utils/redirect.js" line come from? Did you write it yourself?
CodeGrid
CodeGridOP2mo ago
Restarted the dev server Still not working
No description
CodeGrid
CodeGridOP2mo ago
I searched for it online since I wanted to redirect it I don't know where I found it
Jochem
Jochem2mo ago
why didn't you save the file?
CodeGrid
CodeGridOP2mo ago
I did save it
Jochem
Jochem2mo ago
no you didn't
No description
Jochem
Jochem2mo ago
that ball means there's unsaved changes it's an x otherwise or just blank, actually
CodeGrid
CodeGridOP2mo ago
No description
Jochem
Jochem2mo ago
You can also see that there's no uncommitted changes in page.js, which probably means you haven't saved it at all since you last committed:
No description
CodeGrid
CodeGridOP2mo ago
Since it was the same it thinks there was no changes import { InstantRedirect } from "@/utils/redirect.js" Was already here
Jochem
Jochem2mo ago
this also needs to be ./src/utils/*, not .src/utils/* you'll probably have to restart the dev server again after changing that
CodeGrid
CodeGridOP2mo ago
No description
CodeGrid
CodeGridOP2mo ago
Restarted it again Oh wait I saved it and now it workes Thank you for your help!
Jochem
Jochem2mo ago
you really gotta remember to save your code glad to help but yeah, ctrl+s is your friend
CodeGrid
CodeGridOP2mo ago
I will remember that!

Did you find this page helpful?