debugtypescriptCritical
Using eslint with typescript - Unable to resolve path to module
Viewed 0 times
typescriptwithmoduleunableusingresolvepatheslint
Problem
I have this import in my file app.spec.ts:
Which causes this Typescript error
./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
How can I config eslint in such a way that it tries to resolve modules with the .ts and not the .js?
EDIT #1
Content of
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?
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;Solution
You can set the ESLint module import resolution by adding this snippet to your
More informations about resolvers: https://github.com/benmosher/eslint-plugin-import#resolvers.
.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.
Context
Stack Overflow Q#55198502, score: 649
Revisions (0)
No revisions yet.