Импорт собственных файлов
Есть серверное приложение на Node.js, typescript
app.ts
import express from 'express';
import {a} from './temp';
import './temp.ts';
const app = express();
...
temp.ts
console.log(1);
export const a: Number = 5;
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"sourceMap": true,
"strict": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"removeComments": true,
"moduleResolution": "Node16",
"module": "NodeNext",
"target": "ES2022"
}
}
Настроен webpack, eslint. Код, ошибок не показывает, т.е. всё ок. Проблема возникает если запустить сборку:
ERROR in ./app/server/app.ts 9:33-59
Module not found: Error: Can't resolve './temp' in 'F:\Project\app\server'
resolve './temp' in 'F:\Project\app\server'
Если убрать эту строку подключения, то в следующей строке проблемы нет, но и результат иной.
Если добавить расширение в строке import a from './temp.ts, то ошибка следующая:
ERROR in F:\Project\app\server\app.ts
./app/server/app.ts 5:19-39
[tsl] ERROR in F:\Project\app\server\app.ts(5,20)
TS2691: An import path cannot end with a '.ts' extension. Consider importing './temp.js' instead.
Собственно хотелось бы использовать первый вариант, но единственный вариант заставить его работать это использовать // @ts-ignore, а это убивает преимущества ts. Есть ли какое-то решение данной проблемы?