cyrilwanner / next-compose-plugins

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

Next-sass loader bug with Zeit Now v2 next.config.js pattern #13

Closed TLevesque closed 5 years ago

TLevesque commented 5 years ago

Hi, just want to notify a bug with next-sass loader when using the required next.config.js pattern suggested by Zeit team to fix 'now__launder' bug, described there: https://github.com/zeit/next.js/issues/5750

Here is the minimalist github repo to reproduce the problem https://github.com/TLevesque/koa-now It requires to uncomment the lines 12 to 22 in next.config.js and comment the lines 24 to 32 to trigger it.

Here is the error message :

capture d ecran 2018-12-03 a 15 04 41
cyrilwanner commented 5 years ago

Hi @TLevesque
You are right that the proposed solution can't be copied 1:1 when using this plugin because it has to be the function you export from your config file.

But next-compose-plugins has a feature called Optional Plugins which solves the same problem (only including a dependency in a specific phase) and, in my eyes, does that even cleaner.

So your config file would look like this when using next-compose-plugins:

const { withPlugins, optional } = require('next-compose-plugins');
const { PHASE_PRODUCTION_SERVER } = require('next-server/constants');

module.exports = withPlugins([
  [optional(() => require('@zeit/next-sass')), ['!', PHASE_PRODUCTION_SERVER]],
  [optional(() => require('next-images')), ['!', PHASE_PRODUCTION_SERVER]],
]);

I hope that this solves your problem :)

TLevesque commented 5 years ago

Ok, perfect! Thank you

NathanielHill commented 5 years ago

I couldn't get this to work @cyrilwanner. I think because it still requires next-compose-plugins which is not bundled by the builder.