cyrilwanner / next-compose-plugins

💡next-compose-plugins provides a cleaner API for enabling and configuring plugins for next.js
MIT License
736 stars 12 forks source link

[Bug] Breaks on apply a plugin only during development server phase #34

Open ismaelocaramelo opened 4 years ago

ismaelocaramelo commented 4 years ago

Hi there,

First of all, thanks for this amazing plugin which I really find useful. I'm just running an issue where I'd like to run some stuff on just development server phase. To facilitate I'll paste here some of the code:

module.exports = withPlugins(
  [
    [() => console.log('It breaks'), [PHASE_DEVELOPMENT_SERVER]],
  ],
  nextConfig,
)

To avoid the type error the solution would be some safe key checking on updatedConfig https://github.com/cyrilwanner/next-compose-plugins/blob/master/src/compose.js#L102

Sorry I lack of the context to give more useful information on why it may happen. For now what I've made to solve it is by creating a simple plugin.

A generic example:


const myPlugin = (nextConfig = {}, nextComposePlugins) => {
  if (
    PHASE_DEVELOPMENT_SERVER &&
    [PHASE_DEVELOPMENT_SERVER].includes(
      nextComposePlugins && nextComposePlugins.phase,
    )
  )
    // Do some stuff just on development

  return nextConfig
}

Then:

module.exports = withPlugins(
  [
    myPlugin
  ],
  nextConfig
)