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

SWC Transpilation/Minification generates wrong code #58959

Closed
1 task done
milap1296 opened this issue Nov 27, 2023 · 5 comments
Closed
1 task done

SWC Transpilation/Minification generates wrong code #58959

milap1296 opened this issue Nov 27, 2023 · 5 comments
Assignees
Labels
bug Issue was opened via the bug report template. locked

Comments

@milap1296
Copy link

milap1296 commented Nov 27, 2023

Link to the code that reproduces this issue

https://github.com/milap1296/swc-minify-issue

To Reproduce

I am using crypto-js as a dependency and while performing swc-minification it generates a wrong code.

Works correctly in dev environment

  1. yarn install
  2. yarn dev
  3. No client exception

Works incorrectly in production with swcMinify:true

  1. yarn install
  2. yarn build
  3. yarn start
  4. You will be able to see client exception like below
    image
    Error might be because of this Math = Math assignment in the minified code!
    image

Works incorrectly in production with swcMinify:false

  1. yarn install
  2. yarn build
  3. yarn start
  4. You will be able to see same client exception as point:2

Current vs. Expected behavior

It should not throw exception in production and should work like it is in development mode.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.0.2
  eslint-config-next: 14.0.2
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config: {
    swcMinify: true,
    reactStrictMode: true
}

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

SWC transforms

Additional context

No response

@milap1296 milap1296 added the bug Issue was opened via the bug report template. label Nov 27, 2023
@heggland
Copy link

Confirming this bug on nextjs ^14.0.3

I use crypto-js to generate a md5 hash for API call and randomized filename on a form submit function.

image
link to last error - https://legacy.reactjs.org/docs/error-decoder.html/?invariant=423

@milap1296 milap1296 changed the title SWC Minification generate wrong code SWC Transpilation/Minification generates wrong code Nov 27, 2023
@m19
Copy link

m19 commented Dec 1, 2023

I think I am getting a similar issue because of the transpilation/minification, although I am not using crypto-js.

On 14.0.3 I'm getting this on a specific page, only in production:

Uncaught SyntaxError: Identifier 'Audio' has already been declared (at 9436-65c1526a112a4e04.js:4:22913)

On dev mode, it works fine.

If I downgrade back to 14.0.1 it works fine in both dev and prod. So I think it's related to this issue.

@m19 m19 mentioned this issue Dec 1, 2023
1 task
@kdy1 kdy1 self-assigned this Dec 4, 2023
@kdy1
Copy link
Member

kdy1 commented Dec 4, 2023

Closing as fixed by #58517
You can use canary to get it fixed

@kdy1 kdy1 closed this as completed Dec 4, 2023
@milap1296
Copy link
Author

Closing as fixed by #58517 You can use canary to get it fixed

@kdy1 I am still able to reproduce the issue with next@14.0.4-canary.39, could you please check again ?

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 Dec 19, 2023
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. locked
Projects
None yet
Development

No branches or pull requests

4 participants