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

Breaks build process for next-offline #11

Closed NathanielHill closed 5 years ago

NathanielHill commented 6 years ago

TL;DR: when put in the next-compose-plugins array, next-offline doesn't know it's in dev mode

With the following code in next.config.js:

module.exports = withPlugins(
  [
    optimizedImages,
    nextOffline
  ],
  {
    exportPathMap: getRoutes
  }
)

I was running into problems when .next/ did not exist. rm -rf .next/ && next build && cross-env NODE_ENV=development node server.js would work, but rm -rf .next/ && cross-env NODE_ENV=development node server.js failed:

> rm -rf .next/; and cross-env NODE_ENV=development node server.js
Defining routes from exportPathMap
Error: ENOENT: no such file or directory, open '<redacted>.next/BUILD_ID'

It looks like next-offline doesn't receive the dev option and therefore does not exit early like it should in development. I eventually solved the problem by doing the following instead:

module.exports = nextOffline(withPlugins(
  [
    optimizedImages
  ],
  {
    exportPathMap: getRoutes
  }
))
NathanielHill commented 6 years ago

Ran into even more problems with next-offline and had to solve it by removing next-compose-plugins and nesting the plugins like so:

module.exports = optimizedImages(nextOffline({
  webpack: (config) => {
    if (ANALYZE) {
      config.plugins.push(new BundleAnalyzerPlugin({
        analyzerMode: 'server',
        analyzerPort: 8888,
        openAnalyzer: true
      }))
    }
    return config
  },
  exportPathMap: getRoutes
}))

This is working for me, but is ugly and seems like an error prone approach. Do the plugins have to wrap the configuration?

cyrilwanner commented 6 years ago

As we have discussed on slack, I think there is a bug in next-offline because I even have the same error without next-compose-plugins. So I created an issue there (hanford/next-offline#31).

In the meantime, as next-offline is not needed during development builds (at least i think so), you can skip the plugin there and only include it for production builds & exports using the phases config:

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

module.exports = withPlugins(
  [
    optimizedImages,
    [nextOffline, ['!', PHASE_DEVELOPMENT_SERVER]]
  ],
  {
    exportPathMap: getRoutes
  }
)
hanford commented 5 years ago

this can probably be closed now as the issue in next-offline has been.

https://github.com/hanford/next-offline/issues/31

NathanielHill commented 5 years ago

@hanford, so to confirm this bug no longer effects next-offline and we can safely use it with next-compose-plugins without disabling it during development?

NathanielHill commented 5 years ago

I'm happy to close this at any time, since it's clearly in the wrong repo. However, I would like to know if/when this gets entirely resolved so we're no longer required to explicitly disable next-offline during development when using next-compose-plugins :+1:

hanford commented 5 years ago

@NathanielHill false alarm - I spoke a little too soon after seeing some false positives in my local environment.

cyrilwanner commented 5 years ago

I'll close this for now as I think that this status should be tracked in next-offline. However, if you think the issue is still related to next-compose-plugins or need help debugging it, I'm happy to help :)