vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
429 stars 26 forks source link

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

Closed elijahcarrel closed 1 year ago

elijahcarrel commented 1 year ago

Steps to reproduce:

Expected behavior:

Actual behavior:

Workaround:

Version: 0.1.5

This is also as described in https://stackoverflow.com/a/74453475/2736037.

tobiaslins commented 1 year ago

Hey! Thanks for reporting. We'll take a closer look into this. I'll keep you posted!

tobiaslins commented 1 year ago

Hey! I just had a deeper look into this. It seems like you don't have the plugin eslint-import-resolver-typescript which is required that Eslint knows how to resolve this module.

I saw that you have installed eslint-config-next but not using it (which uses this resolver plugin). You did import "plugin:@next/next/recommended" instead. If you change the eslint config to include following, it should work (be sure to use the latest version of eslint-config-next. (The Next.js config includes the eslint plugin you'll need)

 extends: [
    "airbnb-typescript-prettier",
    "next",
  ],

Else you can just install the required plugin: https://github.com/import-js/eslint-import-resolver-typescript

Let me know if it works! :)

Hearmstrong commented 1 year ago

@tobiaslins Would this be the same process in a non-typescript project?

timolins commented 1 year ago

@Hearmstrong It might not be required. There is a JavaScript version as well: https://www.npmjs.com/package/eslint-plugin-import

Note that I haven't tested this out.

tobiaslins commented 1 year ago

Will close this for now. Let us know if you still have problems!

gsheppard commented 1 year ago

I have the next configuration for eslint, but I am still seeing this issue.

extends: [
  'next/core-web-vitals',
  'plugin:@typescript-eslint/recommended',
  'airbnb-base',
  'airbnb-typescript',
  'next',
  'prettier',
],

Admittedly a lot of this config is old and haven't audited it in a while. Nor sure if there are any conflicts happening.

elijahcarrel commented 1 year ago

Thank you so much @tobiaslins! That was exactly my problem and your solution worked. I'm surprised I managed to get this far in my app without actually using eslint-import-resolver-typescript until now 😅.