If npm run start with swcMinify true, unreachable code will be called.
See original GitHub issueWhat version of Next.js are you using?
12.0.7
What version of Node.js are you using?
16.13.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
AWS, Vercel
Describe the Bug
If you run npm run start
with swcMinify set to true, unreachable code will be called.
It is strange that unreachable code exists in the first place, so we should fix it, but I think there are times when such code is created unexpectedly in the world (like us😇).
So, I would like to fix this bug. Please let me know if there’s anything I can do to help! Thanks!
(Sorry if this is a bug in swc and I’m wrong to raise an issue here!)
Translated with www.DeepL.com/Translator (free version)
Expected Behavior
https://github.com/mayone-du/playground/tree/main/report/nextjs-swc
See the repository above. Or the code in ↓
import type { NextPage } from "next";
import { useEffect, useState } from "react";
type Status = "loading" | "error" | "success";
const IndexPage: NextPage = () => {
const [value, setValue] = useState<Status>("loading");
useEffect(() => {
setTimeout(() => {
setValue("success");
}, 1000);
}, []);
if (value === "loading") {
return <div>loading...</div>;
} else if (value === "error") {
return <div>error</div>;
} else {
return <div>success🥰 unreachable code is not called🙆♂️</div>;
}
return <div>unreachable code!!! this is a bug🐛</div>;
// ↑Code that should not be called. swcMinify is called when it is set to true😕.
};
export default IndexPage;
To Reproduce
demo URLs.
in next.config.js ↓swcMinify: true (bug) https://report-nextjs-swc-npwjlueyx-mayone-du.vercel.app/
↓swcMinify: false (ok) https://report-nextjs-swc-bqbpg9h4z-mayone-du.vercel.app/
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top GitHub Comments
Fixed in v12.0.8. But video.js bug still remain.
follow the issue swc-project/swc/issues/3173