eels/next-purge-css-modules

officially support nextjs 13+

Closed this issue · 3 comments

I get this warning when installing with pnpm

 WARN  Issues with peer dependencies found
next-purge-css-modules 1.1.0
  └── ✕ unmet peer next@">= 11.0.0 < 13.0.0": found 13.4.2
next 13.4.2
eels commented

Hey! Good pickup. I believe when I tried this last with Next 13 there had been some changes to the way you need to inject the custom Webpack config so I put that restriction in until I had time to investigate... which I then never did. 😅

I haven't looked at this in a while though, so I can take another stab and see if I can get it working.

eels commented

This has been fixed and released in version 2.0.0.
Next 13 required introducing a breaking change, hence the major version bump.

TL;DR You now need to pass the purge config and Next config separately, like so:

const path = require('path');
const withPurgeCSSModules = require('next-purge-css-modules');

/** @type {import('next').NextConfig} */
const nextConfig = {
  ...
};

/** @type {import('next-purge-css-modules').PurgeConfig} */
const purgeConfig = {
  content: path.join(__dirname, 'src/**/*.{js,jsx,ts,tsx}'),
  enableDevPurge: true,
  safelist: ['body', 'html'],
};

module.exports = withPurgeCSSModules(purgeConfig, nextConfig);

Hi @eels , I only had the chance to test this now.
Seems to work well/ better.

The only error I get now is a type error in the next.config.js

This expression is not callable.
  Type 'typeof import(".../node_modules/.pnpm/next-purge-css-modules@2.0.0_@swc+core@1.3.74_esbuild@0.18.17_next@13.4.12/node_modules/next-purge-css-modules/types/index")' has no call signatures.
image

I think it's something to do when you use require(), because if you do

withPurgeCSSModules.default(purgeConfig, nextConfig)

is the correct type but of course that's not the correct function