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

In Next.js 15 with Turbopack mode, the IIFE is not executing as expected, resulting in a strange bug. #74190

Open
listen936 opened this issue Dec 20, 2024 · 2 comments
Labels
bug Issue was opened via the bug report template. Turbopack Related to Turbopack with Next.js.

Comments

@listen936
Copy link

Link to the code that reproduces this issue

https://github.com/listen936/nextjs_15_turbopack_bug_demo

To Reproduce

  1. npm install
  2. npm run dev

Current vs. Expected behavior

(function _(namespace, path) {
  // The expected output is "", "wrapper", "wrapper.data", "wrapper.data.key"
  // The actual output is "", "wrapper", "data", "key"
  console.debug("####", path)

  for (var i = 0, keys = Object.keys(namespace); i < keys.length; i++) {
    var key = keys[i];
    // --------------------------------------------------------------------------
    console.debug("####", path ? true : false) // always true? why?
    // --------------------------------------------------------------------------
    parent[key] = _(namespace[key], path ? `${path}.${key}` : key, parent[key] || {});
    // --- If the line below is replaced, it will meet the expectations.
    // parent[key] = _(namespace[key], Boolean(path) ? `${path}.${key}` : key, parent[key] || {});
  }
  return parent;
})({
  wrapper: {
    data: {
      key: {}
    },
  }
}, '');

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:27 PDT 2024; root:xnu-11215.41.3~2/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 18.20.1
  npm: 8.19.4
  Yarn: 1.22.10
  pnpm: 8.14.1
Relevant Packages:
  next: 15.1.2 // Latest available version is detected (15.1.2).
  eslint-config-next: 15.1.1
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
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

@listen936 listen936 added the bug Issue was opened via the bug report template. label Dec 20, 2024
@listen936
Copy link
Author

This code is from my actual development experience; I just removed the unnecessary parts.

@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Dec 20, 2024
@listen936
Copy link
Author

update demo code

var root = {};
// namespace builder
(function _(namespace, path, parent) {
  // The expected output is "", "wrapper", "wrapper.data", "wrapper.data.key"
  // The actual output is "", "wrapper", "data", "key"
  console.debug("####", path)

  for (var i = 0, keys = Object.keys(namespace); i < keys.length; i++) {
    var key = keys[i];
    // --------------------------------------------------------------------------
    console.debug("####", path, path ? true : false) // always true? why?
    // --------------------------------------------------------------------------
    parent[key] = _(namespace[key], path ? `${path}.${key}` : key, parent[key] || {});
    // --- If the line below is replaced, it will meet the expectations.
    // parent[key] = _(namespace[key], Boolean(path) ? `${path}.${key}` : key, parent[key] || {});
  }
  return parent;
})({
  wrapper: {
    data: {
      key: {}
    },
  }
}, "", root);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant