Next.js Discord

Discord Forum

Allow complete error message in production

Answered
Masai Lion posted this in #help-forum
Open in Discord
Avatar
Masai LionOP
I try to debug error that i have only on production build.
But even if i run my project locally after build i got this message in console

... specific message is omitted in production builds to avoid leaking sensitive details

Any way to allow full error message in production build ?
Answered by Dan
I gave up on the error file since I think it's fine to give a generic issue (hardcoded text) with an error that occurs with a get request. However, I am running into this issue with server actions too. The way I have been able to work around this is instead of throwing the error in my server action, I return it. Then in my hook (where I set the loading and error state for the UI), I just check for the error property in the data as part of the success response. Seems janky to me but I can't figure anything else out

If I throw from my server action, it doesn't work
View full answer

7 Replies

Avatar
Dan
Does anyone have solution for this? I tried to manually set the text content in the error file which gets rid of the "specific message is omitted in production" but there's also just no text at all. Seems the error file can't make use of any dynamic text or something?
Avatar
Jesse677
Try this.
// next.config.js
module.exports = {
  // Other configurations...

  // Customize webpack configuration
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    // Modify the production configuration
    if (!dev) {
      // Use the DefinePlugin to set process.env.NODE_ENV to 'production'
      config.plugins.push(new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }));

      // Disable minimization so that you can see the unminified code
      config.optimization.minimize = false;
    }

    return config;
  },
};
Avatar
Dan
that didn't work
Avatar
Jesse677
Sorry, try this #How to make error messages not minified
Avatar
Dan
I gave up on the error file since I think it's fine to give a generic issue (hardcoded text) with an error that occurs with a get request. However, I am running into this issue with server actions too. The way I have been able to work around this is instead of throwing the error in my server action, I return it. Then in my hook (where I set the loading and error state for the UI), I just check for the error property in the data as part of the success response. Seems janky to me but I can't figure anything else out

If I throw from my server action, it doesn't work
Answer
Avatar
Jesse677
Sorry you couldn’t find the solution you were looking for
Avatar
Dan
there's nothing I can find about this, it's crazy