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

declare const handled like const during analysis in Turbopack #72576

Closed
timneutkens opened this issue Nov 11, 2024 · 1 comment · Fixed by #72604
Closed

declare const handled like const during analysis in Turbopack #72576

timneutkens opened this issue Nov 11, 2024 · 1 comment · Fixed by #72604
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.

Comments

@timneutkens
Copy link
Member

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/eager-stonebraker-x42f67

To Reproduce

Reproduction requires #71802 to have landed first.

  • Install next@canary
  • Run next dev --turbo
  • Open homepage /
  • It should show my value instead of not set

Current vs. Expected behavior

Currently it shows not set when declare const MY_MAGIC_VARIABLE: string is in the file. Removing it shows the correct my value.

This code does not work with our define handling but works with webpack. When I remove the declare const it works. Looking at the AST output of SWC it seems declare const is a VariableDeclaration but has a property declare: true which it doesn't have for normal const assignment. Looking at the analyzer code we don't take declare: true into account so it's likely skipping replacement for define because we detect a VariableDeclaration already in scope so it doesn't replace.

AST snippet:

    {
      "type": "VariableDeclaration",
      "span": {
        "start": 0,
        "end": 25
      },
      "ctxt": 0,
      "kind": "const",
      "declare": true,
      "declarations": [

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.0.4-canary.5 // Latest available version is detected (15.0.4-canary.5).
  eslint-config-next: N/A
  react: 19.0.0-rc-5c56b873-20241107
  react-dom: 19.0.0-rc-5c56b873-20241107
  typescript: 5.3.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), next build (local)

Additional context

No response

@timneutkens timneutkens added bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. labels Nov 11, 2024
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Nov 11, 2024
@github-actions github-actions bot added the invalid link The issue was auto-closed due to a missing/invalid reproduction link. A new issue should be opened. label Nov 11, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2024
@timneutkens timneutkens reopened this Nov 11, 2024
@timneutkens timneutkens removed the invalid link The issue was auto-closed due to a missing/invalid reproduction link. A new issue should be opened. label Nov 11, 2024
@vercel vercel deleted a comment from github-actions bot Nov 11, 2024
@vercel vercel unlocked this conversation Nov 11, 2024
kdy1 added a commit to swc-project/swc that referenced this issue Nov 11, 2024
**Description:**

`declare const MY_MAGIC_VARIABLE: string` is not a variable declaration.

**Related issue:**

 - vercel/next.js#72576
@kdy1 kdy1 closed this as completed in cd82914 Nov 12, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant