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 4 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
5 changes: 5 additions & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -634,6 +634,11 @@ export default async function getBaseWebpackConfig(
loggedIgnoredCompilerOptions = true
}

if (!useSWCLoader && config.experimental.fontLoaders) {
Log.error('`experimental.fontLoaders` requires SWC but found Babel config.')
hanneslund marked this conversation as resolved.
Show resolved Hide resolved
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` requires SWC but found Babel config./
)
})
})
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'],
},
},
},
}