In my file app.spec.ts, I am encountering an issue with the following import statement:
import app from './app';
This is resulting in a Typescript error:
2:17 error Unable to resolve path to module './app' import/no-unresolved
Although ./app.ts does exist, the error persists until I compile the .ts file into a .js file. Once compiled, the error disappears.
Since eslint should support Typescript, it should ideally resolve modules using the .ts extension rather than the .js extension.
I have also included Typescript information in my eslint
config file:
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
}
Is there a way to configure eslint so that it attempts to resolve modules using the .ts extension instead of the .js extension?
EDIT #1
Below is the 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;