Skip to content

bug: imported function becomes not defined with --turbopack #79594

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

Open
vanaigr opened this issue May 24, 2025 · 2 comments
Open

bug: imported function becomes not defined with --turbopack #79594

vanaigr opened this issue May 24, 2025 · 2 comments
Labels
linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.

Comments

@vanaigr
Copy link

vanaigr commented May 24, 2025

Description

import { err } from '@/lib/utils';
export async function POST() {
    console.log('first', err);
    for(let i = 0; i < 0; i++) return err();
    console.log('second', err);
}

This route handler successfully prints err in the first console.log(), but then something happens and it fails with err is not defined when trying to print it a second time.

This only happens with --turbopack.

Link to the code that reproduces this issue

https://github.com/vanaigr/next-not-defined-bug

Edited by @timneutkens: Simplified reproduction: https://codesandbox.io/p/github/vanaigr/next-not-defined-bug/csb-5qq4l8/draft/keen-field?file=%2Fapp%2Froute.ts%3A1%2C1-7%2C1. Just run npm run dev and open /.

To Reproduce

  1. pnpm dev in a terminal
  2. Go to http://localhost:3000/Dashboard
  3. Observe that terminal has output with the following error:
> next@0.1.0 dev /home/artarar/tmp/next
> next dev --turbopack

   ▲ Next.js 15.1.8 (Turbopack)
   - Local:        http://localhost:3000
   - Network:      http://192.168.1.102:3000

 ✓ Starting...
 ✓ Ready in 1544ms
 ○ Compiling /Dashboard ...
 ✓ Compiled /Dashboard in 7.1s
 GET /Dashboard 200 in 7590ms
 ✓ Compiled /Dashboard/loadDashboardData in 410ms
first [Function: err]
 ⨯ ReferenceError: err is not defined
    at POST (app/Dashboard/loadDashboardData/route.ts:5:26)
  3 |     console.log('first', err);
  4 |     for(let i = 0; i < 0; i++) return err();
> 5 |     console.log('second', err);
    |                          ^
  6 | }
  7 |
 ⨯ ReferenceError: err is not defined
    at POST (app/Dashboard/loadDashboardData/route.ts:5:26)
  3 |     console.log('first', err);
  4 |     for(let i = 0; i < 0; i++) return err();
> 5 |     console.log('second', err);
    |                          ^
  6 | }
  7 |
 POST /Dashboard/loadDashboardData 500 in 789ms
  1. Run pnpm dev-without-turbopack
  2. Go to http://localhost:3000/Dashboard
  3. Observe both first and second print statements are successful:
> next@0.1.0 dev-without-turbopack /home/artarar/tmp/next
> next dev

   ▲ Next.js 15.1.8
   - Local:        http://localhost:3000
   - Network:      http://192.168.1.102:3000

 ✓ Starting...
 ✓ Ready in 3.3s
 ○ Compiling /Dashboard ...
 ✓ Compiled /Dashboard in 2.3s (591 modules)
 GET /Dashboard 200 in 3375ms
 ○ Compiling /Dashboard/loadDashboardData ...
 ✓ Compiled /Dashboard/loadDashboardData in 901ms (599 modules)
first [Function: err]
second [Function: err]
 ⨯ [Error: No response is returned from route handler '/home/artarar/tmp/next/app/Dashboard/loadDashboardData/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler.]
 ⨯ [Error: No response is returned from route handler '/home/artarar/tmp/next/app/Dashboard/loadDashboardData/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler.]
 POST /Dashboard/loadDashboardData 500 in 1291ms

Current vs. Expected behavior

The route handler shouldn't crash with err is not defined.

Provide environment information

/bin/sh: 1: yarn: not found

Operating System:
  Platform: linux
  Arch: x64
  Version: #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024
  Available memory (MB): 5865
  Available CPU cores: 2
Binaries:
  Node: 23.11.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.7.1
Relevant Packages:
  next: 15.1.8 // Latest available version is detected (15.1.8).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

PACK-4738

@timneutkens
Copy link
Member

Thanks for the report, verified the reproduction and simplified it a bit to make it easier to dig into:

https://codesandbox.io/p/github/vanaigr/next-not-defined-bug/csb-5qq4l8/draft/keen-field?file=%2Fapp%2Froute.ts%3A1%2C1-7%2C1

@timneutkens timneutkens added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Jun 2, 2025
@mischnic
Copy link
Contributor

mischnic commented Jun 3, 2025

This is probably also fixed by #77964

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants