kwonoj/swc-plugin-coverage-instrument

@next/font error: Font loaders must be called and assigned to a const in the module scope

meakbiyik opened this issue · 2 comments

Hi, thanks for the wonderful module that allows using covreage with next.js defaults! I have a bug that prevents me from using this plugin though: when using @next/font with the following code

import '../styles/globals.css';
import type { AppProps } from 'next/app';
import { Roboto } from '@next/font/google';

const roboto = Roboto({
  weight: ['400', '500', '700'],
  subsets: ['latin'],
});

export default function App({ Component, pageProps }: AppProps) {
  return (
      <Component {...pageProps} className={roboto.className} />
  );
}

adding the plugin gives the following error in compilation:

Font loaders must be called and assigned to a const in the module scope

Any help is appreciated!

s0hv commented

I had the same error and fixed it by putting /* istanbul ignore next */ on the line before const roboto = Roboto(...)

That works wonderfully, thanks a lot! I did not know that istanbul ignore comments were respected by this plugin, it might be a good idea to note this in the README.