Next.js: react hooks don't work in SSR when distDir is setted in next.config.js

Created on 28 Mar 2019  路  3Comments  路  Source: vercel/next.js

Bug report

The react hooks will not work. If you have changed the setting of distDir.

Describe the bug

I use the [with Firebase Hosting and Typescript example] like architecuture and
If I use hooks in SSR , the error of 銆嶩ooks can only be called inside the body of a function component.銆廻appens.

To Reproduce

  1. set distDir: './dist/next' setting in next.config.js
  2. use hooks in SSR
  3. above error happens
  4. by commenting out distDir setting, hooks works well

System information

  • OS: [macOS]
  • Browser (if applies) [chrome]
  • Version of Next.js: [e.g. 8.0.3]

Most helpful comment

@tky5622 I had this exact same issue and was able to fix it by running npm run clean and then npm run dev again. I used the same starter example code as you as well.

All 3 comments

Doesn't sound like a bug in Next.js, rather you're doing something non-standard in your directory structure that maybe loads 2 versions of React? It's generally not needed to set distDir.

@tky5622 I had this exact same issue and was able to fix it by running npm run clean and then npm run dev again. I used the same starter example code as you as well.

@yongla I have the exact same error.
What does the clean script in your package.json ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

renatorib picture renatorib  路  3Comments

kenji4569 picture kenji4569  路  3Comments

irrigator picture irrigator  路  3Comments

jesselee34 picture jesselee34  路  3Comments

formula349 picture formula349  路  3Comments