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?
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;
"plugins": ["@typescript-eslint"]
? Docs github.com/typescript-eslint/typescript-eslint/tree/master/… – OnusUnable to resolve path to module './app'
– Coelostatsettings: { '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! ) – Cantatricemodule.exports = { resolve: { extensions: ['.js', '.ts'] } };
bit should be in your webpack config! – Cantatriceapp.ts
file ? – Conscientiousapp.ts
:) – Coelostatnode_modules
, reinstalling, and restarting TS server – Inoperable