Unable to locate the next/google/font module in my Typescript project

Issue With Import Syntax for Font Types

The documentation here provides an example:

import { <font-name> } from 'next/google/font';

This code compiles successfully, but throws a "module not found" error at runtime.

However, in this discussion, it suggests using:

import { <font-name> } from '@next/google/font';

Using this syntax results in a compile time error.

It would be helpful to clarify whether the "@" symbol is required or not. The discrepancy between the two syntaxes is confusing!

Context: nx Mono-repo Environment

Notably, this issue arises in a NextJs project within an nrwl nx mono-repo.

I attempted to update the package.json with:

"@types/next": "13.1.1",

Unfortunately, this did not resolve the problem.

It's important to note that the package.json file is located at the root of the mono-repo, as sub-projects do not have their own separate package.json files.

Attempted Solutions In Type Declaration Files

Within the specific app's directory, I created an index.d.ts file and added:

declare module 'next/font/google'

and

declare module '@next/font/google'

Neither of these declarations fixed the issue.

Similar Issue on Stackoverflow

I also checked this thread on stackoverflow, but it did not offer a solution.

Exploring Yarn Lock File

Looking into the yarn.lock file, I found an entry referencing next inside the @nrwl namespace. I tried using '@nrwl/next/google/font' based on this information, but it did not work either.

"@nrwl/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="224c475a566213170c1a0c1a">[email protected]</a>":
  version "15.8.8"
  resolved "https://registry.npmjs.org/@nrwl/next/-/next-15.8.8.tgz"
  integrity sha512-h7sYBf8ljyfXyoSCgiHxukB/AyZsHNL8g+vSVmr7iCkVd6IgFIa1n3myM7vaALAVrJ0EccXYdK7yuKHbVvfLnA==
  dependencies:
    "@babel/plugin-proposal-decorators" "^7.14.5"
    "@nrwl/devkit" "15.8.8"
    "@nrwl/js" "15.8.8"
    "@nrwl/linter" "15.8.8"
    "@nrwl/react" "15.8.8"
    "@nrwl/workspace" "15.8.8"
    "@svgr/webpack" "^6.1.2"
    chalk "^4.1.0"
    copy-webpack-plugin "^10.2.4"
    dotenv "~10.0.0"
    express "^4.18.1"
    fs-extra "^11.1.0"
    http-proxy-middleware "^2.0.6"
    ignore "^5.0.4"
    semver "7.3.4"
    ts-node "10.9.1"
    tsconfig-paths "^4.1.2"
    tsconfig-paths-webpack-plugin "4.0.0"
    url-loader "^4.1.1"
    webpack-merge "^5.8.0"

Answer №1

Before the Release of Next.js 13.2.0

  • In order to use fonts in your Next.js project, you had to manually add the package @next/font by running either yarn add @next/font or npm i @next/font

After Next.js 13.2.0 (Versions 13.2.0 and above)

  • With the release of Next.js 13.2.0, the fonts package is now included by default, eliminating the need for an extra installation (if you have @next/font installed, make sure to remove it). You will also need to import from the native package using next/font instead of @next/font (without the @)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Resetting CSS animations using animation-delay

My aim is to animate a series of images on my landing page using Next.js and SCSS. The issue arises when I try to add dynamic animations that reset after each cycle. The delay in the animation causes the reset to also be delayed, which disrupts the flow. I ...

Decorator in React that automatically sets the display name to match the class name

Is there a way to create a decorator that will automatically set the static property displayName of the decorated class to the name of the class? Example usage would be: @NamedComponent class Component extends React.Component { \* ... *\ } ...

Retrieve the variance between two arrays and store the additions in AddedList and the removals in RemovedList using typescript

I am still getting the hang of Typescript and I am trying to figure out the best solution for my issue. I have two arrays, A and B, and I need to identify the difference between them in relation to array A. The goal is to separate the elements that were ad ...

"Encountering an issue with getAuth() validation in Firebase while using Next

I've been exploring different authentication methods in NextJS, but I find the Firebase approach more comfortable. However, I'm encountering an error with authentication that I can't seem to fix. Can anyone help? Here are the snippets of co ...

The user fails to be redirected following wallet authentication in NextJS

Can someone help me figure out how to redirect the user to the onboard page after successfully connecting to their wallet? Web3Button doesn't seem to be returning anything and I'm stuck. import React, { useEffect } from "react"; import ...

TypeScript combined with Vue 3: Uncaught ReferenceError - variable has not been declared

At the start of my <script>, I define a variable with type any. Later on, within the same script, I reference this variable in one of my methods. Strangely, although my IDE does not raise any complaints, a runtime error occurs in my console: Referenc ...

What are the steps to deploy a Next.js static website on Vercel without the need to build it first

I recently created a static website and can generate the output files by executing this command locally: next build && next export. This command creates an output folder named out. I want to upload the out folder directly to Vercel, but I am unsu ...

Troubleshooting a Cache Issue in Your Next.js Application

Whenever I attempt to run 'npm run build', an error crops up that seems to be linked to the css and fonts. Unfortunately, I am unsure of how to tackle this problem. It's perplexing as the app functions perfectly fine in development mode. Th ...

Troubleshooting the issue with a styled subcomponent in React using Styled Components

Recently, I've delved into React and have been experimenting with creating a Modal component using styled components. My goal is to achieve a similar effect to Framer Motion's motion.div, but utilizing styled components instead. Currently, I hav ...

Is there a way to ensure that in React (Typescript), if a component receives one prop, it must also receive another prop?

For instance, consider a component that accepts the following props via an interface: interface InputProps { error?: boolean; errorText?: string; } const Input = ({error, errorText}: InputProps) => { etc etc } How can I ensure that when this com ...

Tips for avoiding a form reload on onSubmit during unit testing with jasmine

I'm currently working on a unit test to ensure that a user can't submit a form until all fields have been filled out. The test itself is functioning correctly and passes, but the problem arises when the default behavior of form submission causes ...

A problem has occurred in Next.js where FileReader is not recognized and is causing a Reference

Exploring the latest features of Next.js 13 with the /app directory, I encountered an issue while using the FileReader in a basic client-side component that manages an input form. Here is a brief overview of the code: "use client"; import React, ...

Retrieving data and parameter data simultaneously from the ActivatedRoute

I am currently utilizing Angular and have a webpage where I need to send data to another page. Transmit an array of selected values Generate multiple records (associating with a model) this.activatedRoute.data.subscribe(({ model] }) => { setTim ...

Looking to start using WebDriverIO and Typescript with the WDIO wizard? Here's how to get it

I'm in the process of setting up a WebdriverIO project using TypeScript and Cucumber. I followed the steps provided by the wizard, which was pretty straightforward. I opted for Cucumber, TypeScript, and the page object model. This setup created a tes ...

Is there a way to effectively eliminate an array of objects in JavaScript or TypeScript and alter the object structure simultaneously?

I am seeking solutions to restructure an object that has multiple arrays of objects so that I can access the object directly. console.log(value.data.summary[0].data) Instead of accessing arrays in this manner, I want to modify my data structure. Is there ...

Select the API Endpoints You Want to Enable on Next.js

I have been experimenting with certain endpoints locally that may not be suitable for production. I need to restrict access to these endpoints when deploying my code. Is there a way to achieve this in Next.js? Do I need to modify next.config.mjs or create ...

What could be causing the error with firebase Sign In in next.js?

I set up a sign in page to enter email and password for Firebase authentication. The sign up process works fine, but I'm encountering an issue with the sign in functionality. 'use client' import { useState } from 'react'; import { ...

Unusual class title following npm packaging

Currently, I am working on developing a Vue 3 library with TypeScript. We are using Rollup for bundling the library. Everything works as expected within the library itself. However, after packing and installing it in another application, we noticed that th ...

The useRouter function was accessed, but the query object it received was found

Trying to understand routing in Next.JS, but struggling with accessing the query object. The file path is: ./src/pages/[test]/index.tsx import { useRouter } from 'next/router'; export default function Test() { const router = useRouter(); co ...

Understanding how to leverage styles.module.scss for implementing personalized styling within react-big-calendar

I'm currently working with the react-big-calendar library in order to develop a customized calendar. However, I've encountered an issue where the SCSS styling is not being applied correctly. export const JobnsCalendar = () => ( <Calendar ...