Replies: 2 comments 11 replies
-
What Next.js version do you have. Looks like up to certain SWC versions, this didn't work so well. Here for example ~ upgrading to I tried in the latest stable Next.js with: const isDev = () => process.env.NODE_ENV === 'development';
// This conditional check will NOT be removed by Next.js during the build process,
// even when NODE_ENV is set to 'development'. The `isProd` function check remains in the output.
if (isDev()) {
const devValue = 'value';
console.log('1337-420', devValue);
} On a page, and that code didn't make it to production. Maybe I am doing something wrong, this kind of dead code elimination has always been a bit fragile. Could you share more details? |
Beta Was this translation helpful? Give feedback.
11 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I noticed that dead code elimination does not work as expected when using functions with constant return values. Here's an example to illustrate the issue:
It looks like wrapping the check in a function prevents Next.js/SWC from optimizing it away. Is there any workaround for this, or is it something that would require internal changes to Next.js, like a double-pass build to eliminate dead code?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions