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

swcMinify: true does not produce an usable build with v12.1.5 #36127

Closed
1 task done
ribeaud opened this issue Apr 13, 2022 · 42 comments
Closed
1 task done

swcMinify: true does not produce an usable build with v12.1.5 #36127

ribeaud opened this issue Apr 13, 2022 · 42 comments
Assignees
Labels
bug Issue was opened via the bug report template.

Comments

@ribeaud
Copy link

ribeaud commented Apr 13, 2022

Verify canary release

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

Provide environment information

 $ npx --no-install next info

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
    Binaries:
      Node: 16.13.1
      npm: 8.1.2
      Yarn: 1.22.18
      pnpm: N/A
    Relevant packages:
      next: 12.1.5
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

Not relevant

How are you deploying your application? (if relevant)

next start after a next build

Describe the Bug

Locally (running the application locally, in my IDE), everything looks good. Our tests are green as well. Only the PROD artefact is somehow rubbish.

When accessing the homepage, this is what we get in the console:

console

When clicking on one of the links displayed, this is what I get:

error_decoder

Expected Behavior

No error messages in the console, application is running properly and swcMinify is set to true, like it used to be for v12.1.0 (application was NOT working with the releases from v12.1.1 to v12.1.4).

The expected behavior could be achieved if I set swcMinify to false in the configuration file.

To Reproduce

Kindly follow instructions given in the README.md, Production-like local deployment.

More info on the problem could be found here and there.

Please, let me know if you have questions, or whether I should deeply investigate in a given direction, or if I can do anything here to help.

Thanks in advance for your time and investigation.

@ribeaud ribeaud added the bug Issue was opened via the bug report template. label Apr 13, 2022
@bonesoul

This comment was marked as off-topic.

@powerfulyang
Copy link

powerfulyang commented Apr 15, 2022

same here

/**
 * Create a code check from a regex.
 *
 * @param {RegExp} regex
 * @returns {(code: Code) => code is number}
 */
function regexCheck(regex) {
  return check

  /**
   * Check whether a code matches the bound regex.
   *
   * @param {Code} code Character code
   * @returns {code is number} Whether the character code matches the bound regex
   */
  function check(code) {
    return code !== null && regex.test(String.fromCharCode(code))
  }
}

Code above will not work fine.
Throw ReferenceError: check is not defined

@kdy1
Copy link
Member

kdy1 commented Apr 15, 2022

I fixed the issue reported by @powerfulyang (swc-project/swc#4338), but not sure if this issue is related to this issue.

@kdy1
Copy link
Member

kdy1 commented Apr 15, 2022

I'm not sure how can I test the fix

Seems like you are invoking next.js in docker, right? If so, yarn link will not help.
Is there a way to run the webapp without docker?

@smitpatel1010
Copy link

@kdy1 Can you add this change swc-project/swc#4250 in nextjs to fix infinite loops?

@kdy1
Copy link
Member

kdy1 commented Apr 15, 2022

@smitpatel1010 Of course, I included it in #36187

@smitpatel1010
Copy link

Oh great. Thanks 🙂

@balazsorban44
Copy link
Member

@ribeaud looking at your reproduction, it seems a bit complicated. Could you please try to create a more minimal one that's focusing on the issue?

I recommend removing any pages/components/technologies that do not contribute to the bug you are experiencing (eg. I'm sure Docker and most of the stuff in the repo are not contributing to the issue here). This will help us verify and fix any bugs much faster. 👍

kodiakhq bot pushed a commit that referenced this issue Apr 15, 2022
This PR updates swc crates to swc-project/swc@b8d9a58


- Closes #35811
- Closes #34811
  - I tested with https://github.com/balazsorban44/issue-34811

<img width="1840" alt="image" src="https://user-images.githubusercontent.com/29931815/163574875-d7392c4c-b1f1-4503-aac1-35a26c9d7ec2.png">

- Closes #34715
  - I tested with https://github.com/cungminh2710/nextjs-swc-mapbox

<img width="1840" alt="image" src="https://user-images.githubusercontent.com/29931815/163574677-9733dd69-9938-4e3e-b2f1-bfbd6db9e20c.png">


 - This fixes the bug reported in the comment (#36127 (comment)), but I didn't test the issue itself.
powerfulyang added a commit to powerfulyang/powerfulyang.com that referenced this issue Apr 16, 2022
1. react@18 下 font-optimization 有 BUG, Temporary fix:
optimizeFonts: false; vercel/next.js#35835 (comment)
2. next@12.1.5 swcMinify 有 BUG, 12.1.4 还是好的, Temporary fix:
swcMinify: false; vercel/next.js#36127 (comment)
3. 当前 next@12.1.5 和 @sentry/nextjs@6.19.6 的情况有 BUG, 不会上传 sourcemap 不知道以前是否是好; getsentry/sentry-javascript#3579 (comment)
powerfulyang added a commit to powerfulyang/powerfulyang.com that referenced this issue Apr 16, 2022
1. react@18 下 font-optimization 有 BUG, Temporary fix:
optimizeFonts: false; vercel/next.js#35835 (comment)
2. next@12.1.5 swcMinify 有 BUG, 12.1.4 还是好的, Temporary fix:
swcMinify: false; vercel/next.js#36127 (comment)
3. 当前 next@12.1.5 和 @sentry/nextjs@6.19.6 的情况有 BUG, 新发现仅仅 Windows 有问题, 不会上传 sourcemap 不知道以前是否是好; getsentry/sentry-javascript#3579 (comment)
CrescentKohana pushed a commit to CrescentKohana/shingetsu-blog that referenced this issue Apr 18, 2022
@ribeaud
Copy link
Author

ribeaud commented Apr 20, 2022

@balazsorban44 makes perfectly sense. However I am not sure being able to do it before coming week-end. What I definitely can do is to test any canary release you want.

@timneutkens
Copy link
Member

@ribeaud no rush on providing the code but we can't investigate it further for your particular case without it. Can you try the latest canary version? A bunch of changes to the minifier were applied.

@arnovanstaden
Copy link

arnovanstaden commented Apr 21, 2022

swcMinify: true is causing the exact same problem for me. After removing it from next.config the production build is starting smoothly

@timneutkens
Copy link
Member

@arnovanstaden can you provide a reproduction for your case? We've generally found that comments on these issues tend to be completely different minifier bugs that have to be investigated separately.

@CrescentKohana
Copy link

CrescentKohana commented Apr 21, 2022

Same issue here with swcMinify: true. Was working fine on Next.js 12.1.4 and broke on 12.1.5. Also tried v12.1.6-canary.4 which didn't fix it either.

The issue can be reproduced by running the few simple commands listed for production on https://github.com/Luukuton/shingetsu-blog/tree/main/frontend with the following as .env.local:

NEXT_PUBLIC_STRAPI_API_URL=https://strapi.luukuton.fi
NEXTAUTH_URL=http://localhost:3000
SECRET=1234
JWT_SIGNING_PRIVATE_KEY={"kty":"oct","kid":"1234","alg":"HS256","k":"1234"}

Remember the change the swcMinify to true in next.config.mjs as well.

Errors:
Application error: a client-side exception has occurred (see the browser console for more information).

ReferenceError: check is not defined
    at Object.7011 (75-8b0d76e33d9d9da7.js:1:226386)
    at a (webpack-dab0b2f9bb1be3f3.js:1:157)
    at Module.334 (index-94cc969871e15009.js:1:289)
    at a (webpack-dab0b2f9bb1be3f3.js:1:157)
    at index-94cc969871e15009.js:1:151
    at main-fd09345e2a348c4f.js:1:25750

@kdy1
Copy link
Member

kdy1 commented Apr 21, 2022

@Luukuton Seems like it's fixed by 9456fc6

image

@powerfulyang
Copy link

powerfulyang commented Apr 21, 2022

https://nextjs.org/docs/advanced-features/source-maps

!!! Set productionBrowserSourceMaps true in next.config.js can get full error trace.

@CrescentKohana
Copy link

@Luukuton Seems like it's fixed by 9456fc6

Nice! Looks good.

!!! Set productionBrowserSourceMaps true in next.config.js can get full error trace.

Thanks 😄. I'll remember this in the future if I have to debug something.

@ribeaud
Copy link
Author

ribeaud commented Apr 21, 2022

The latest canary (12.1.6-canary.5) does a much better job. Still NOT working on my end, but now getting following error in the console:

console

@seanparmelee
Copy link
Contributor

We have been running into this issue in one of our apps as well (even on the latest canary). In our case, the following error is thrown:

TypeError: j is not a function
    at r.exports (util.js:1:46666)
    at Object.112 (util.js:1:46666)
    at __nccwpck_require__ (util.js:1:46666)
    at Object.749 (util.js:1:46666)
    at __nccwpck_require__ (util.js:1:46666)
    at Object.715 (util.js:1:46666)
    at __nccwpck_require__ (util.js:1:46666)
    at Object.3 (util.js:1:46666)
    at __nccwpck_require__ (util.js:1:46666)
    at Object.650 (util.js:1:46666)

After some process of elimination, the culprit turned out to be some code that was using

import { isString } from 'util';

And removing that code makes the error goes away.

I pushed up a simple reproduction here in hopes it helps get to the root cause of the issue (this form of it anyway): https://github.com/seanparmelee/nextjs-36127-reproduction

@kdy1
Copy link
Member

kdy1 commented Apr 22, 2022

@seanparmelee
image

It will be fixed by #36351

(I used my own script to replace next-swc binary)

@VeronikaSergiyenko
Copy link

VeronikaSergiyenko commented Apr 28, 2022

I tried release https://github.com/vercel/next.js/releases/tag/v12.1.6-canary.13 that should contain fix from #36351
but still doesn't work
зображення

@kdy1
Copy link
Member

kdy1 commented Apr 28, 2022

@VeronikaSergiyenko I think it will be fixed by #36535

React now uses google closure compiler as their minifier, and it triggered a bug of swc minifier.
So I disabled the problematic pass for now and I'm working on a full fix for alias analyzer

powerfulyang added a commit to powerfulyang/powerfulyang.com that referenced this issue May 3, 2022
@Rafcin
Copy link

Rafcin commented May 26, 2022

I just want to add to this, that I ran into a similar issue whereupon deployment I receive invariant 138 saying "Maximum depth exceeded", and disabling swcMinify solves the issue for now. https://reactjs.org/docs/error-decoder.html/?invariant=185

@kdy1
Copy link
Member

kdy1 commented May 26, 2022

@Rafcin Did you try the latest canary? If so, can you provide a repro?

@Rafcin
Copy link

Rafcin commented May 26, 2022

@kdy1 I just tested a deployment with 12.1.7-canary.16 and it threw the same issue. The repo is private, but if you need anything specific let me know!

@terryli0095
Copy link

Is the solution just to downgrade to 12.10.0? Our build was working with 12.1.6. Migrated to Material UI 5 . And part of the codebase that's unrelated to the MUI started breaking after minify

@kdy1
Copy link
Member

kdy1 commented Jun 8, 2022

@terryli0095 You can provide more information, like repro case, so I can fix it

@danilowoz
Copy link

danilowoz commented Jun 20, 2022

@kdy1 I can reproduce this error using a dependency as example:

next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  swcMinify: true,
};

module.exports = nextConfig;
package.json
{
  "name": "swc-test",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@codemirror/text": "^0.19.6",
    "next": "12.1.6",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@types/node": "18.0.0",
    "@types/react": "18.0.14",
    "@types/react-dom": "18.0.5",
    "eslint": "8.18.0",
    "eslint-config-next": "12.1.6",
    "typescript": "4.7.4"
  }
}
index.tsx
import type { NextPage } from "next";
import { Text } from "@codemirror/text";

const Home: NextPage = () => {
  const length = Text.of(["Hello World"]).length;

  return <p>{length}</p>;
};

export default Home;

The variable value should always return 11, but if you set the swcMinify to true it returns -1. As far I could understand, this option is generating a different output of the following piece of code.

// Wrong
swcMinify: true,

// @codemirror/text
constructor(a, b=function(a) {
  for (let b of a)
    b.length;
  return -1
} 

// Correct
swcMinify: false,

// @codemirror/text
constructor(a, b=function(a) {
  let e = -1
  for (let b of a)
    e += b.length + 1;
  return e
}

Hope it helps


Edit: it has been fixed on Canary

@kdy1
Copy link
Member

kdy1 commented Jun 20, 2022

  let e = -1
  for (let b of a)
    e + b.length + 1;
  return e

Is this typo?

@danilowoz
Copy link

Sorry, yes. The right output is:
Screenshot 2022-06-20 at 11 34 32

@kdy1
Copy link
Member

kdy1 commented Jun 20, 2022

@danilowoz swc-project/swc#5013

I checked it and it was already fixed long time ago. What's your next.js version?

@danilowoz
Copy link

It's 12.1.6, I just created this project from scratch, and other users also reported this problem recently.

@kdy1
Copy link
Member

kdy1 commented Jun 20, 2022

@danilowoz Can you try canary?

@danilowoz
Copy link

Yep, I can confirm that it has been fixed on canary. Thanks, @kdy1

CrescentKohana added a commit to CrescentKohana/shingetsu-blog that referenced this issue Jun 30, 2022
@OskarD
Copy link

OskarD commented Aug 3, 2022

Any progress on this? I want to disable it to debug a bug that doesn't happen in local development mode for some reason

@kdy1
Copy link
Member

kdy1 commented Aug 3, 2022

@OskarD All debuggable issues are fixed. Others did not provide any information.

@OskarD
Copy link

OskarD commented Aug 3, 2022

@OskarD All debuggable issues are fixed. Others did not provide any information.

I'm probably doing something wrong, but with 12.2.3 and this config:

    swcMinify: false,
    compress: false

I'm getting this kind of error:

Error: No credentials
    at e.<anonymous> (70-0c006eaa97bdd322.js:1:193655)
    at 70-0c006eaa97bdd322.js:1:185254
    at Object.next (70-0c006eaa97bdd322.js:1:185359)
    at a (70-0c006eaa97bdd322.js:1:184095)

Is there something I'm missing here?

@kdy1
Copy link
Member

kdy1 commented Aug 3, 2022

Is it really related to swc minifier?

    swcMinify: false,

Is this typo?

@OskarD
Copy link

OskarD commented Aug 3, 2022

Is it really related to swc minifier?

    swcMinify: false,

Is this typo?

Sorry, I thought this thread was for disabling minifying. I'm using Webpack so my problem is not related, my apologies

@ribeaud
Copy link
Author

ribeaud commented Sep 26, 2022

Hi. Just this short notice to let you know that, after many unsuccessful releases, I was able to reactivate swcMinify: true on our end with v12.3.1.

I do not know what exactly solves it though: whether we changed something relevant on our side, or whether it is due to some changes on your side. Anyway, let's appreciate this momentum and let me tell you thank you!

@ribeaud
Copy link
Author

ribeaud commented Sep 26, 2022

Should I close it?

@kdy1
Copy link
Member

kdy1 commented Sep 26, 2022

Nice! I think we can close this issue for now.
Thank for the notice!

@kdy1 kdy1 closed this as completed Sep 26, 2022
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. 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 Oct 27, 2022
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.
Projects
None yet
Development

No branches or pull requests