Closed NathanielHill closed 5 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?
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
}
)
this can probably be closed now as the issue in next-offline has been.
@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?
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:
@NathanielHill false alarm - I spoke a little too soon after seeing some false positives in my local environment.
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 :)
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
: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, butrm -rf .next/ && cross-env NODE_ENV=development node server.js
failed:It looks like
next-offline
doesn't receive thedev
option and therefore does not exit early like it should in development. I eventually solved the problem by doing the following instead: