Encountering the following error message: "ESLint: Unable to locate module path '@vercel/analytics/react' (import/no-unresolved)", despite the package and path being existent within the file

ESLint is throwing an error message that says:

ESLint: Unable to resolve path to module '@vercel/analytics/react'.(import/no-unresolved)

The issue arises in this line of code:

import { Analytics } from '@vercel/analytics/react';

This error occurred while following the instructions from the Vercel quickstart guide for Next.js.

To summarize, the steps instructed were:

1- Install the package using NPM

npm install @vercel/analytics

2- In the /pages/_app.tsx file, import it as follows:

import { Analytics } from '@vercel/analytics/react';

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Component {...pageProps} />
      <Analytics />
    </>
  );
}

export default MyApp;

The packages used in my project are:


    "next": "^12.1.0",
    "react": "17.0.2",

    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    ...

The folder structure of the installed NPM package is:

/node_modules/@vercel
  analytics/
    dist/
      react/
        index.cjs
        index.d.ts
        index.js
      index.cjs
      index.d.ts
      index.js
    package.json
    tsconfig.json
    ...

I noticed that the actual path in node_modules is '@vercel/analytics/dist/react' rather than just '@vercel/anaylitics/react' as mentioned in the code provided.

When clicking on the imported variable Analytics, my IDE directs me to the definition in node_modules at

@vercel/analytics/dist/react/index.d.ts
.

My ESLint configuration related to the import/ module is:

settings: {
  'import/resolver': {
    node: {
      extensions: ['.js', '.jsx', '.ts', '.tsx'],
      paths: ['src'],
    },
  },
},

If I modify the import statement to:

import { Analytics } from '@vercel/analytics/dist/react'

ESlint no longer throws an error, but TypeScript does with the message:

TS2305: Module '"@vercel/analytics/dist/react"' has no exported member 'Analytics'.

Despite that, the IDE successfully finds the definition and the export statement is present, indicating it should work correctly.

What adjustments should be made to the ESlint config or steps taken to resolve this issue without any linting or compiler errors?

Answer №1

When utilizing the eslint tool, it is necessary to incorporate the plugin: eslint-import-resolver-typescript with a version no less than 3.1.0.

This particular version has also been integrated into eslint-config-next in the following Pull Request. Therefore, updating to the most recent package (13.0.4) should address this issue.

Furthermore, there is an ongoing problem on our Github repository along with a proposed solution available at: https://github.com/vercel/analytics/issues/18#issuecomment-1318424277

Answer №2

I submitted a query to vercel for guidance on resolving the same issue I encountered. It is likely that such issues are common with beta products. Meanwhile, I temporarily added the line below to my _app.js file, which allowed me to circumvent the linting error and successfully deploy to vercel. I have confirmed that analytics are working as expected, indicating that it may simply be a minor bug.

...
// eslint-disable-next-line import/no-unresolved
import { Analytics } from "@vercel/analytics/react";
...

Answer №3

Give this method a try

//tsconfig.json
"compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@vercel/analytics/react": ["./node_modules/@vercel/analytics/dist/react"]
    }
}

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

Simultaneous Activation of Hover Effects on Multiple Elements

I have an array of objects that I'm iterating over. Here is the array: const socialLinks = [ { id: 1, child: ( <> <FaLinkedin className='text-2xl' /> Linkedin </> ), hre ...

Firebase will automatically log users out after one hour of inactivity

After conducting thorough research, I have learned that Firebase updates a refresh token every hour because Firebase ID tokens expire after one hour. It is mentioned that the automatic refreshing of tokens by Firebase occurs without any action required fro ...

Retrieving information using useSWR. Advancing to the Next Image

When fetching data from the backend URL without a host, in the Next Image I pass the source with the host. However, the requested URL of the image ends up being the page's pathname + the URL without the host. How does this happen? const { data: pa ...

Centralized platform for accessing node and npm installers that adhere to Nexus standards

I am searching for a nexus-compliant repository where I can find a node installer that aligns with Nexus guidelines (an alternative to http://nodejs.org/dist/). Situation : In our Java environment, Maven handles our builds. We recently integrated a JavaS ...

Is there a way to retrieve the client's IP address from the server side within a Next.js application?

How can I determine the user's time zone and location in order to generate a server-side page tailored to their specific location and time zone? I am struggling to retrieve the user's IP address from the request or the localhost IP address (127.0 ...

Exploring Next.js with getStaticPaths for multi-language support

In my current Next.js project, I am working on implementing multiple locales for dynamic pages using i18n. Within my next.config.js file, the following configuration is set: module.exports = { i18n: { locales: ["en-US", "da-DK", "se-SE", "no-NO", "n ...

Console not logging route changes in NextJS with TypeScript

My attempt to incorporate a Loading bar into my NextJs project is encountering two issues. When I attempt to record a router event upon navigating to a new route, no logs appear. Despite my efforts to include a loading bar when transitioning to a new rout ...

What steps should I take to fix the npm error when trying to install -g yarn?

I'm trying to execute the command to install yarn using npm: npm install -g yarn However, I encountered an error message: npm ERR! code ENOENT npm ERR! syscall spawn bash npm ERR! path C:\Users\DigiMax\AppData\Roaming\npm&bs ...

How to change router.push in NextJS to navigate to non-shallow routes

On my search page, I encounter a problem when users make consecutive searches without refreshing the page. Even though the query in the URL updates, the products on the page remain unchanged. I attempted to solve this by using router.push("/search-pa ...

To use the npm generator-ionic installation, make sure to have yo@>=1.0.0 installed in your

While attempting to set up generator-ionic, I encountered the following fatal error: EPEERINVALID <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="375052595245564358451a5e5b565c575b6f1d54585459">[email protected]</a&g ...

Optimizing Next.js links for seamless functionality when deployed on AWS Cloudfront

I'm currently in the process of setting up a prototype project with Next.js by utilizing a Static html export (specifically, next export) and then transferring the output to AWS S3 for Cloudfront to serve. In my /pages directory, I have the following ...

Why is the presence of ""dev" true" necessary in package-lock.json file?

Can you explain the significance of "dev" true in the package-lock.json file? I have noticed that it gets updated automatically during npm operations. Can this be removed and if so, how? ...

I encountered a frustrating issue of receiving a 400 Bad Request error while attempting to install

I am currently in the process of installing Angular CLI using npm to incorporate Angular 4 into several projects. Unfortunately, I keep encountering a 400 Bad Request error. Has anyone else faced this issue before and found a solution? I have already searc ...

Transforming named functions in const or class constructors with Eslint and Typescript: a guide

Lately, I've been relying heavily on the code snippet from an answer that I requested: function sameValuesAsKeys<K extends string>(...values: K[]): {readonly [P in K]: P} { const ret = {} as {[P in K]: P} values.forEach(k => ret[k] = k); ...

Issue with next-intl plugin when choosing enum-based values is not functioning correctly

For my next.js project (version 13.4), I was in need of next-intl translation support. I followed the official example provided at The example mentioned to define the following code in the 'en.json' file: "message": "{gender, sele ...

When running my code on my local machine (MAC OSX), I encountered an issue where the "htmlextra" reporter was not found for generating the HTML report

Upon running the newman run command with the parameter -r htmlextra, I encountered the following message. Even though I had already installed htmlextra globally using -g, I am able to execute it when creating a newman .js file. Can you provide advice on wh ...

Achieve a fade-in effect on an element with TailwindCSS when clicked

Currently working on an app and facing a challenge with fading the menu in and out when clicking a button. The menu is rendering on click using state, but struggling to achieve the fade in / fade out effect. Interestingly, when tweaking the opacity value d ...

Creating PDF files with dynamic image paths retrieved from the database can be easily achieved using various npm packages. Below are the

As I work on building a software using express-mongodb-ejs, I've encountered some challenges with generating and downloading PDFs. While I've explored several npm packages for this purpose, I've found that I am unable to generate a PDF with ...

Is localStorage.getItem() method in NextJS components behaving differently?

I'm working on my nextjs application and I wanted to utilize the power of localstorage for storing important data throughout my app. Within the pages directory, specifically in the [slug].tsx file, I implemented the following logic: export default fu ...

I keep running into errors whenever I try to run npm install in my React JS project. The only way for me to successfully install dependencies is by using npm install --force. How can I go about resolving these

I am encountering this error message while working on my project: npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @mui/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681b1c11040d1b ...