我的文件app.spec.ts中有此导入:
import app from './app';
Run Code Online (Sandbox Code Playgroud)
导致此Typescript错误的原因
2:17 error Unable to resolve path to module './app' import/no-unresolved
Run Code Online (Sandbox Code Playgroud)
./app.ts确实存在,但是我还没有将.ts文件编译成.js文件。一旦将.ts文件编译为.js,错误就会消失。
但是,由于eslint应该使用typescript,因此应该使用.ts而不是.js解析模块。
我还在eslint配置文件中添加了打字稿信息:
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
}
Run Code Online (Sandbox Code Playgroud)
如何配置eslint,使其尝试使用.ts而不是.js解析模块?
干杯!
编辑#1
内容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!' }; …Run Code Online (Sandbox Code Playgroud)