Next.js Discord

Discord Forum

console.log not appearing clientside

Answered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
Fully describe what you're trying to accomplish
I am trying to get my console.log output to appear in the browser dev tools console.

Include the relevant chunks of code in your post
Created a reproduction here: https://codesandbox.io/p/sandbox/dank-leftpad-pqxg9j

Steps I took:
1. Set up a brand new project with npx create-next-app@latest

2. Created my component:
"use client"
import { useEffect } from "react"

const MyComponent = (props: any): JSX.Element => {
  console.log("should log in both server and browser")

  useEffect(() => {
    console.log("should log in the browser");
  }, [])

  return (
    <div>
      Component content here
    </div>
  )
}

export default MyComponent


export default MyComponent


3. Placed the component on the default page, page.tsx:
import MyComponent from './MyComponent'

export default function Home() {
  return (
    <main >
      <MyComponent />
    </main>
  )
}


I should expect to see console.log twice in the browser, and once on the server, but I don't see anything.

Include the logs/errors you are receiving
None

Explain what you've tried to solve the issue
Set up the above minimal reproduction of it. Not sure how to proceed forward.
Answered by Giant panda
It ended up being my node version (for my local). Not sure why this would cause issues. I was using 16.13.x. updated to 16.20.x and it started working as expected. really strange issue.
View full answer

4 Replies

it seems to be working fine here. I can see the log in the codesandbox terminal (server) and in my own browser console (client)
Giant pandaOP
yeah I think my computer is gaslighting me or something. I still can't see output. Thanks for confirming what you can see, though.
Giant pandaOP
It ended up being my node version (for my local). Not sure why this would cause issues. I was using 16.13.x. updated to 16.20.x and it started working as expected. really strange issue.
Answer
btw you should upgrade to at least node 18 now