Unverified Commit bac00ba7 authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

@next/font migration warning (#46036)

Print warning with migration instructions if `@next/font` is in deps.

Fixes NEXT-483

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

---------
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
parent ae3442c3
# Built-in `next/font`
#### Why This Error Occurred
Starting with Next.js 13.2, `next/font` is built-in to Next.js and no longer needs to be installed. The `@next/font` package will be removed in Next.js 14.
#### Possible Ways to Fix It
Run the `built-in-next-font` codemod to automatically uninstall `@next/font` and change `@next/font` imports to `next/font`:
```sh
npx @next/codemod built-in-next-font .
```
### Useful Links
- [Codemods](https://nextjs.org/docs/advanced-features/codemods)
- [Optimizing Fonts](https://nextjs.org/docs/basic-features/font-optimization)
...@@ -794,6 +794,10 @@ ...@@ -794,6 +794,10 @@
"title": "app-static-to-dynamic-error", "title": "app-static-to-dynamic-error",
"path": "/errors/app-static-to-dynamic-error.md" "path": "/errors/app-static-to-dynamic-error.md"
}, },
{
"title": "built-in-next-font",
"path": "/errors/built-in-next-font.md"
},
{ {
"title": "version-staleness", "title": "version-staleness",
"path": "/errors/version-staleness.md" "path": "/errors/version-staleness.md"
......
...@@ -170,9 +170,10 @@ const nextDev: CliCommand = async (argv) => { ...@@ -170,9 +170,10 @@ const nextDev: CliCommand = async (argv) => {
} }
async function preflight() { async function preflight() {
const { getPackageVersion } = await Promise.resolve( const { getPackageVersion, getDependencies } = (await Promise.resolve(
require('../lib/get-package-version') require('../lib/get-package-version')
) )) as typeof import('../lib/get-package-version')
const [sassVersion, nodeSassVersion] = await Promise.all([ const [sassVersion, nodeSassVersion] = await Promise.all([
getPackageVersion({ cwd: dir, name: 'sass' }), getPackageVersion({ cwd: dir, name: 'sass' }),
getPackageVersion({ cwd: dir, name: 'node-sass' }), getPackageVersion({ cwd: dir, name: 'node-sass' }),
...@@ -184,6 +185,23 @@ const nextDev: CliCommand = async (argv) => { ...@@ -184,6 +185,23 @@ const nextDev: CliCommand = async (argv) => {
' Read more: https://nextjs.org/docs/messages/duplicate-sass' ' Read more: https://nextjs.org/docs/messages/duplicate-sass'
) )
} }
const { dependencies, devDependencies } = await getDependencies({
cwd: dir,
})
// Warn if @next/font is installed as a dependency. Ignore `workspace:*` to not warn in the Next.js monorepo.
if (
dependencies['@next/font'] ||
(devDependencies['@next/font'] &&
devDependencies['@next/font'] !== 'workspace:*')
) {
Log.warn(
'Your project has `@next/font` installed as a dependency, please use the built-in `next/font` instead. ' +
'The `@next/font` package will be removed in Next.js 14. ' +
'You can migrate by running the `built-in-next-font` codemod. Read more: https://nextjs.org/docs/messages/built-in-next-font'
)
}
} }
const port = getPort(args) const port = getPort(args)
......
/* eslint-env jest */
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
createNextDescribe(
'Deprecated @next/font warning',
{
files: {
'pages/index.js': '',
},
dependencies: {
react: 'latest',
'react-dom': 'latest',
'@next/font': 'canary',
},
skipStart: true,
},
({ next }) => {
it('should warn if @next/font is in deps', async () => {
await next.start()
await check(() => next.cliOutput, /compiled client and server/)
expect(next.cliOutput).toInclude(
'please use the built-in `next/font` instead'
)
await next.stop()
await next.clean()
})
it('should not warn if @next/font is not in deps', async () => {
// Remove @next/font from deps
const packageJson = JSON.parse(await next.readFile('package.json'))
delete packageJson.dependencies['@next/font']
await next.patchFile('package.json', JSON.stringify(packageJson))
await next.start()
await check(() => next.cliOutput, /compiled client and server/)
expect(next.cliOutput).not.toInclude(
'please use the built-in `next/font` instead'
)
await next.stop()
await next.clean()
})
}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment