Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint says it cannot resolve a path to a module that does exist

ErrorUnable to resolve path to module 'react'. import/no-unresolved

Short answer

import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver. By default it only knows Node's rules and the .js extension. Check that the package is installed, then tell the plugin about your .jsx or .tsx files and, for TypeScript aliases, add the TypeScript resolver.

  • Applies to eslint-plugin-import 2.x, Node.js 22, TypeScript 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out whether the failing name is a package or one of your own files. For a package, ask npm whether it is installed; for a file, check its real name and extension.

    npm ls react
    npx eslint --print-config src/App.jsx | grep -A8 "import/resolver"
  2. 2Match what you see, then jump to its fix

    1. 1The path in the message is a bare name such as 'react' and npm ls shows nothingThe package is not installed in this projectFix
    2. 2Relative imports like './Button' fail while 'Button.jsx' sits next to the fileThe file is .jsx or .tsx and the resolver only looks for .jsFix
    3. 3Imports through an alias such as '@/components/Header' fail, or .ts files are not found, in a project that builds fineTypeScript paths or aliases that the Node resolver cannot seeFix
    4. 4The import works on macOS or Windows but the rule still reports itFile name casing differs from the importFix

What does the error look like?

  • Unable to resolve path to module 'react'. import/no-unresolved

Cause 1 of 4

The package is not installed in this project

1Check

The rule resolves an import to a module on the local filesystem using Node's lookup. If node_modules does not contain the package, the lookup fails, whatever your editor shows.

npm ls react

2Fix

Install the package where the code that imports it lives (in a monorepo, that workspace), then run ESLint again.

npm install react react-dom

3Verify

npm lists the package and the error is gone on the next lint run.

npm ls react
npx eslint src

Confirmed by github.com

Did this fix it?

Cause 2 of 4

The file is .jsx or .tsx and the resolver only looks for .js

1Check

The plugin's default for import/extensions is ['.js'] (['.js', '.jsx'] with the react shared config). Files with other extensions are not found when you import them without the extension.

ls src/components | grep -i button

2Fix

List the extensions on the Node resolver in your ESLint settings.

// .eslintrc.cjs
module.exports = {
  settings: {
    'import/resolver': {
      node: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
    },
  },
};

3Verify

Lint the file that failed.

npx eslint src/App.jsx

Confirmed by github.com

Did this fix it?

Cause 3 of 4

TypeScript paths or aliases that the Node resolver cannot see

1Check

The default Node resolver knows nothing about tsconfig paths. The plugin's TypeScript setup needs a parser and a separate resolver package.

grep -n "paths" tsconfig.json

2Fix

Install the TypeScript parser and resolver, then enable both the typescript and node resolvers in the settings.

npm install --save-dev @typescript-eslint/parser eslint-import-resolver-typescript

// eslint.config.js (flat config)
settings: {
  'import/resolver': {
    typescript: true,
    node: true,
  },
},

3Verify

Lint a file that imports through the alias.

npx eslint src/app/page.tsx

Confirmed by github.com

Did this fix it?

Cause 4 of 4

File name casing differs from the import

1Check

The rule's caseSensitive option is on by default and reports a path whose casing does not match the file on a case-insensitive filesystem.

git ls-files src | grep -i header

2Fix

Rename the file or fix the import so both use the same casing.

git mv src/components/header.jsx src/components/Header.jsx

3Verify

Lint again; the path is accepted.

npx eslint src

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Keep resolver settings next to the ESLint config in version control, so CI and editors resolve imports the same way.
  • Run the linter in CI after a clean npm ci, which exposes packages that only exist on one laptop.
  • Use one casing style for component file names and never rename only the case outside git mv.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

TypeScript says a JavaScript module implicitly has an any type

Could not find a declaration file for module 'react-materialize'. 'path/to/module-name.js' implicitly has an 'any' type.

TypeScript found the JavaScript file but no types for it, and noImplicitAny turns that into an error.

2 causes, each with a fix

Web apps

TypeScript says a function lacks an ending return statement

A function with a declared return type, such as Promise<string>, shows the red line under the type

TypeScript found a way for your function to reach its closing brace without returning a value, while the declared return type does not allow undefined.

4 causes, each with a fix

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.