Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font loader with babel error #41151

Merged
merged 8 commits into from Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions errors/babel-font-loader-conflict.md
@@ -0,0 +1,14 @@
# Babel and Font loader conflict

#### Why This Error Occurred

You have tried to use `experimental.fontLoaders` with a custom babel config. When your application has a custom babel config you opt-out of the Next.js Compiler which is required to use `experimental.fontLoaders`.

#### Possible Ways to Fix It

- Remove your custom babel config and use the Next.js Compiler

### Useful Links

- [Next.js Compiler](https://nextjs.org/docs/advanced-features/compiler)
- [Customizing Babel Config](https://nextjs.org/docs/advanced-features/customizing-babel-config)
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -737,6 +737,10 @@
{
"title": "nonce-contained-invalid-characters",
"path": "/errors/nonce-contained-invalid-characters.md"
},
{
"title": "babel-font-loader-conflict",
"path": "/errors/babel-font-loader-conflict.md"
}
]
}
Expand Down
10 changes: 10 additions & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -646,6 +646,16 @@ export default async function getBaseWebpackConfig(
loggedIgnoredCompilerOptions = true
}

if (babelConfigFile && config.experimental.fontLoaders) {
Log.error(
`"experimental.fontLoaders" is enabled which requires SWC although Babel is being used due to custom babel config being present "${path.relative(
dir,
babelConfigFile
)}".\nSee more info here: https://nextjs.org/docs/messages/babel-font-loader-conflict`
)
process.exit(1)
}

const getBabelLoader = () => {
return {
loader: require.resolve('./babel/loader/index'),
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/next-font/babel.test.ts
@@ -0,0 +1,33 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { join } from 'path'

describe('@next/font/google babel', () => {
const isNextStart = (global as any).isNextStart
let next: NextInstance

if (!isNextStart) {
it('should only run on next start', () => {})
return
}

beforeAll(async () => {
next = await createNext({
skipStart: true,
files: new FileRef(join(__dirname, 'babel')),
dependencies: {
'@next/font': 'canary',
},
})
})
afterAll(() => next.destroy())

test('Build error when using babel', async () => {
await expect(next.start()).rejects.toThrow(
'next build failed with code/signal 1'
)
expect(next.cliOutput).toMatch(
/"experimental.fontLoaders" is enabled which requires SWC although Babel is being used due to custom babel config being present ".babelrc"./
)
})
})
4 changes: 4 additions & 0 deletions test/e2e/next-font/babel/.babelrc
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": []
}
3 changes: 3 additions & 0 deletions test/e2e/next-font/babel/pages/index.js
@@ -0,0 +1,3 @@
export default function Page() {
return <p>Hello world</p>
}
Expand Up @@ -5,8 +5,14 @@ import webdriver from 'next-webdriver'
import { join } from 'path'

describe('font-loader-in-document-error', () => {
const isDev = (global as any).isNextDev
let next: NextInstance

if (!isDev) {
it('should only run on next dev', () => {})
return
}

beforeAll(async () => {
next = await createNext({
files: {
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/next-font/font-loader-in-document/next.config.js
@@ -0,0 +1,9 @@
module.exports = {
experimental: {
fontLoaders: {
'@next/font/google': {
subsets: ['latin'],
},
},
},
}