2

in next.js (next.config.js) I am trying to export 2 plugins:

withImages and the current environment, I tried the following but it doesn't work,

the env variable get as undefined

const withImages = require('next-images')
const withPlugins = require("next-compose-plugins");

const { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } = require('next/constants')


function currEnv(phase) {
    console.log('heresdssdsdrere');
    // when started in development mode `next dev` or `npm run dev` regardless of the value of STAGING environmental variable
    const isDev = phase === PHASE_DEVELOPMENT_SERVER
    // when `next build` or `npm run build` is used
    const isProd = phase === PHASE_PRODUCTION_BUILD && process.env.STAGING !== '1'
    // // when `next build` or `npm run build` is used
    // const isStaging =
    //     phase === PHASE_PRODUCTION_BUILD && process.env.STAGING === '1'

    console.log(`isDev:${isDev}  isProd:${isProd} `)

    const env = {
        isDev: isDev,
        isProd: isProd
    }

    // next.config.js object
    return {
        env,
    }
}


module.exports = withPlugins(
    [
        withImages
    ],
    {
        env: currEnv
    }
);
Yuval Levy
  • 2,397
  • 10
  • 44
  • 73
  • did you solve your question? I have the same issue. Could you help? – Asking Nov 12 '20 at 06:46
  • Does this answer your question? [Configure multiple next plugins: withMDX, withBundleAnalyzer](https://stackoverflow.com/questions/67135699/configure-multiple-next-plugins-withmdx-withbundleanalyzer) – Midhun Darvin Jul 10 '21 at 08:20

0 Answers0