Since Next.js 9.2, there is no more need to use next-css
and withCSS
or withStyle
. Next.js natively handles CSS imports.
Since these may come with Webpack issues (see this issue: Having trouble importing CSS in NextJs), here's the way to configure loaders with webpack. In your terminal:
npm install file-loader --save-dev
npm install url-loader --save-dev
Then replace (or complete) your next.config.js
file with the following:
module.exports = {
cssModules: true,
webpack: (config, options) => {
config.node = {
fs: "empty",
};
config.module.rules.push({
use: [
options.defaultLoaders.babel,
{
loader: "url-loader?limit=100000",
},
{
loader: "file-loader",
},
],
});
return config;
},
};
Don't forget to remove any mention of withCSS
, withStyle
or next-css
since they may cause some errors to happen.