File size: 955 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { NodePath, types } from 'next/dist/compiled/babel/core'
import type { PluginObj } from 'next/dist/compiled/babel/core'

export default function NextPageDisallowReExportAllExports(): PluginObj<any> {
  return {
    visitor: {
      ImportDeclaration(path: NodePath<types.ImportDeclaration>) {
        if (
          [
            '@next/font/local',
            '@next/font/google',
            'next/font/local',
            'next/font/google',
          ].includes(path.node.source.value)
        ) {
          const err = new SyntaxError(
            `"next/font" requires SWC although Babel is being used due to a custom babel config being present.\nRead more: https://nextjs.org/docs/messages/babel-font-loader-conflict`
          )
          ;(err as any).code = 'BABEL_PARSE_ERROR'
          ;(err as any).loc =
            path.node.loc?.start ?? path.node.loc?.end ?? path.node.loc
          throw err
        }
      },
    },
  }
}