Using eslint with typescript - Unable to resolve path to module
Solution 1
You can set the ESLint module import resolution by adding this snippet to your .eslintrc.json
configuration file:
{
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
...
}
More informations about resolvers: https://github.com/benmosher/eslint-plugin-import#resolvers.
Solution 2
I had the same problem and I was only able to fix it by adding the typescript plugin to .eslintrc
, using the extends
option in .eslintrc
extends: [
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
],
Solution 3
This does it for me:
.eslintrc.js
{
...
settings: {
...
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
moduleDirectory: ['node_modules', 'src/'],
},
},
}
}
Solution 4
This was the only solution that worked for me.
First, you need to install this package:
yarn add -D eslint-import-resolver-typescript
Then add this to your .eslintrc
file so it can load the alias settings from your tsconfig.json
into ESLint:
{
"settings": {
"import/resolver": {
"typescript": {}
},
},
}
Solution 5
When using "eslint": "6.8.0" with "typescript": "3.8.3" besides adding the following to .eslintrc
:
"settings": {
"import/resolver": {
"node": {
"paths": ["src"],
"extensions": [".js", ".jsx", ".ts", ".tsx"],
}
},
}
You also need to add this line to tsconfig.json
under compilerOptions
:
"compilerOptions": {
...
// Base directory to resolve non-relative module names.
"baseUrl": "src",
...
}
Related videos on Youtube

Maxime Dupré
Updated on April 22, 2022Comments
-
Maxime Dupré 8 months
I have this import in my file app.spec.ts:
import app from './app';
Which causes this Typescript error
2:17 error Unable to resolve path to module './app' import/no-unresolved
./app.ts does exist, but I have not compiled the .ts file into a .js file. As soon as I compile the .ts file to a .js, the error goes away.
However, since eslint is supposed to work with typescript, it should resolve modules with the .ts and not the .js.
I've also added the typescript information in my
eslint
config file:"parser": "@typescript-eslint/parser", "parserOptions": { "project": "./tsconfig.json" }
How can I config eslint in such a way that it tries to resolve modules with the .ts and not the .js?
Cheers!
EDIT #1
Content of
app.ts
:import bodyParser from 'body-parser'; import express from 'express'; import graphqlHTTP from 'express-graphql'; import { buildSchema } from 'graphql'; const app = express(); const schema = buildSchema(` type Query { hello: String } `); const root = { hello: () => 'Hello world!' }; app.use(bodyParser()); app.use('/graphql', graphqlHTTP({ schema, rootValue: root, graphiql: true, })); export default app;
-
Jasmonate almost 4 yearsHave you added
"plugins": ["@typescript-eslint"]
? Docs github.com/typescript-eslint/typescript-eslint/tree/master/… -
Maxime Dupré almost 4 yearsHey @Jasmonate, thanks for the answer! So I just added this config, and while I can now do some Typescript-specific linting, it does not solve my problem. I still get
Unable to resolve path to module './app'
-
Abulafia almost 4 yearsHave you tried adding this into your .eslintrc?
settings: { 'import/resolver': 'webpack' }
(I'm assuming the code builds OK. If not, you will need to tell webpack to resolve .ts/.tsx files as well, which means adding something like: ``` module.exports = { resolve: { extensions: ['.js', '.ts'] } }; ``` or whatever file extensions you want to be able to import! ) -
Abulafia almost 4 yearsThe above comment is incomplete, I'm afraid! I ran out of editing time having pressed enter too soon! The
module.exports = { resolve: { extensions: ['.js', '.ts'] } };
bit should be in your webpack config! -
Eastrall almost 4 yearsCan you add the content of your
app.ts
file ? -
Maxime Dupré almost 4 yearsHey @Abulafia! Unfortunately, I am not using webpack...
-
Maxime Dupré almost 4 years@Eastrall I edited the question with the content of
app.ts
:) -
KyleMit over 1 yearIf all else fails, you can try deleting
node_modules
, reinstalling, and restarting TS server
-
-
Izhaki over 3 yearsI believe the other answer is the right solution for this.
-
Epoch almost 3 yearsThis is what worked for me; even including the "plugin:import/*" extensions didn't do anything. The
moduleDirectory
line pointing to'src/'
was the key to get this working on my end. -
Tevon Strand-Brown almost 3 yearsThis worked for me as well. Note that HAD to add the "moduleDirectory" key.
-
Robin Zimmermann over 2 yearsI needed both the "settings" and the "rules", as described in this answer. Thanks!
-
Yogi over 2 yearsbarking!! Hats off👏🏻
-
Yan Yankowski over 2 yearsAdding the moduleDirectory: ['node_modules', 'myModules/'] indeed helped. I've seen a partial version of this solution without 'moduleDirectory' property and it didn't work. This one did the trick.
-
underscore over 2 yearsworks after adding moduleDirectory: ['node_modules', 'src/']
-
Tomas Vancoillie over 2 yearsGreatly appreciated to add the
baseUrl
options, saved my day -
charlax over 2 yearsThanks! Adding
"plugin:import/typescript"
is what fixed it for me. -
httpete about 2 yearsIn my case I had to add .d.ts to the list- the package csstypes only contains an index.d.ts: "settings": { "import/resolver": { "node": { "paths": [ "src" ], "extensions": [ ".js", ".jsx", ".d.ts", ".ts", ".tsx" ] } } }
-
Ryan almost 2 yearsThis seemed to solve the
Unable to resolve path to module
error, but now I'm still getting a bunch ofMissing file extension "tsx" for [...]
-
Ryan almost 2 yearsAhh,
'import/extensions': 0,
helped: stackoverflow.com/questions/56064609/… -
brianyang almost 2 yearsthis is the only one that worked for me, just add this line and save. the error went right away!
-
MasterWil almost 2 yearsNote that you need to 1. place "plugin:import/typescript" after "airbnb-base". 2. Remember to add
"import"
inplugins
section. -
Evgeniya Manolova almost 2 yearsThis can also solve the case when the eslint configuration is shared between several projects and therefore located in a top-level folder. Listing all projects' paths in the
paths
property solves the eslint error. -
semkeijsper over 1 yearThis is the only one that worked for me when using a monorepo and a path alias to a different package.
-
Jalal over 1 year@Semx11, Same here!
-
Volodymyr Bobyr over 1 yearnow i get
Missing file extension "ts" for <file>
-
Volodymyr Bobyr over 1 year^ fixed with: stackoverflow.com/a/59268871/12658818
-
c0dezer019 over 1 yearIt's one of those days! I had this problem, used this solution, and it didn't work. Tried it again several hours later and then it works. Weird!
-
Diego Alberto Zapata Häntsch over 1 yearthis doesn't solve the problem only it turn off the rule
-
Sandeep vashisth about 1 yearThis worked for me using the same config in .eslintrc.json in the typescript react project.
-
Kristóf Dombi about 1 yearFor some reason by just having "plugin:import/typescript", did not solved this problem for me. The solution was to use this: github.com/alexgorbatchev/eslint-import-resolver-typescript
-
June about 1 yearit's only solution for me thx ;)
-
FR073N about 1 year` "typescript": {} ` did the trick for me.
-
ofundefined 12 monthsIndeed. My "babel-module" had only {}
-
Nicolas 11 monthsThat worked for me!! Thank you :)
-
julianYaman 11 monthsThanks for this solution, the other ones didn't really help in my use case
-
Paul P 10 monthsThis worked for me with Quasar v1 (
quasar create <project> --branch v1
) andairbnb-base
ESLint config. -
SalahAdDin 9 monthsIt didn't work for me.
-
Kristi Jorgji 9 monthsthis works with nextjs, thanks
-
VimNing 9 monthsHey, hey you, 2022 readers! Take a look at my one-line solution: stackoverflow.com/a/71629047/5290519
-
shamaseen 9 monthsthis worked for me, one thing to note is if you are using an IDE and the error is shown by the IDE, make sure that you check it with the command line, cause your IDE may be misconfigured.
-
Oleksandr Danylchenko 8 monthsThanks! Missing
eslint-import-resolver-typescript
was the issue! -
Nivethan 7 monthsthis solved the path alias issue in a react-native cli project
-
German Attanasio 7 months@pedro_A you are the real MVP!
-
Hazy 7 monthsAdd my voice to also say this is the only solution that also worked for me after trying pretty much everything else that I came across to solve this problem
-
Chunky Chunk 6 monthsignoring a problem and fixing a problem are very different solutions.
-
VimNing 6 months@ChunkyChunk: But the accepted one didn't work during my writing.
-
Juanma 6 monthsthis is what did the trick for me. I was missing this step. Thanks