Next.js: Error: Invalid hook call on minimal setup

Created on 22 Apr 2020  路  3Comments  路  Source: vercel/next.js

Bug report

Describe the bug

On a brand new next.js project using create-next-app, introducing a hook causes the app to crash and the Error: Invalid hook call. Hooks can only be called inside of the body of a function component error.

yarn dev successfully starts the app
next dev causes this error

To Reproduce

  1. next-create-app hook-test
  2. cd hook-test

  3. Modify pages/index.js to include a hook

import React, { useState } from 'react'
const Home = () => {
  const [myVar, setMyVar] = useState()
  return <div>hook test</div>
}
export default Home
  1. next dev

Expected behavior

It should work as expected

System information

  • OS: macOS
  • Browser: Chrome, Safari
  • Version of Next.js: 9.3.5
  • Version of Node.js: 12.16.1

[email protected]
[email protected]
[email protected]
[email protected]

Most helpful comment

It sounds like you are installing Next.js globally, this isn't supported and should be run locally from your project with yarn next dev or yarn dev if you've configured the dev script in your package.json to next dev as you mentioned

All 3 comments

Okay for some reason when I start the app up with next dev it fails, but if I use yarn dev it works

It sounds like you are installing Next.js globally, this isn't supported and should be run locally from your project with yarn next dev or yarn dev if you've configured the dev script in your package.json to next dev as you mentioned

Resolved. Thank you @ijjk .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rauchg picture rauchg  路  3Comments

olifante picture olifante  路  3Comments

formula349 picture formula349  路  3Comments

ghost picture ghost  路  3Comments

swrdfish picture swrdfish  路  3Comments