Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: fetchData is not defined #33088

Closed
mjr opened this issue Jan 7, 2022 · 2 comments · Fixed by #33201
Closed

ReferenceError: fetchData is not defined #33088

mjr opened this issue Jan 7, 2022 · 2 comments · Fixed by #33201

Comments

@mjr
Copy link
Contributor

mjr commented Jan 7, 2022

Run next info (available from version 12.0.8 and up)

Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64
Binaries:
Node: 14.18.2
npm: 6.14.15
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.0.8-canary.19
react: 17.0.2
react-dom: 17.0.2

What version of Next.js are you using?

12.0.8-canary.19

What version of Node.js are you using?

14.18.2

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

After upgrading next to version 12 i get a ReferenceError: fetchData is not defined when using early return without braces inside useEffect, in version 11 it works as expected.

Running the next command in development works as expected, but next build and next start the error happens.

React.useEffect(() => {
  if (query === '') return

  function getFetchUrl() {
    return 'https://hn.algolia.com/api/v1/search?query=' + query
  }

  async function fetchData() {
    const res = await fetch(getFetchUrl())
    const data = await res.json()
    setData(data)
  }

  fetchData()
}, [query])

next-bug

Expected Behavior

Expected to work without the need to add braces.

To Reproduce

Clone this project https://github.com/mjr/next-bug.
Run next build and then PORT=3000 next start.
Open localhost:3000 e open the console to see the error.

@mjr mjr added the bug Issue was opened via the bug report template. label Jan 7, 2022
@balazsorban44 balazsorban44 added area: SWC Minify and removed bug Issue was opened via the bug report template. labels Jan 7, 2022
@balazsorban44
Copy link
Member

The issue seems to be related to swcMinify: true. I added this to our backlog. In the meantime, swcMinify: false should help you out.

This was referenced Jan 8, 2022
@kodiakhq kodiakhq bot closed this as completed in #33201 Jan 14, 2022
kodiakhq bot pushed a commit that referenced this issue Jan 14, 2022
This PR is a bit big because AST definitions are modified recently because previous AST defs were too error-prone.
It will prevent plugin authors from making some common mistakes.


 - Closes #33088
 - Closes #31084
 - Closes #33283
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 13, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
This PR is a bit big because AST definitions are modified recently because previous AST defs were too error-prone.
It will prevent plugin authors from making some common mistakes.


 - Closes vercel#33088
 - Closes vercel#31084
 - Closes vercel#33283
nevilm-lt pushed a commit to nevilm-lt/next.js that referenced this issue Apr 22, 2022
This PR is a bit big because AST definitions are modified recently because previous AST defs were too error-prone.
It will prevent plugin authors from making some common mistakes.


 - Closes vercel#33088
 - Closes vercel#31084
 - Closes vercel#33283
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants