首页 > 解决方案 > How can I properly import TSX files using relative paths?

问题描述

I have a React/Typescript/webpack project.

Everything works fine, except that when I import a 'tsx' file I need to supply the entire path or it will fail to compile.

I want to just write:

import './styles.less';
import { TestComponent } from './TestComponent.tsx';

While the less import works fine, the tsx import fails unless I write:

import './styles.less';
import { TestComponent } from '@src/components/TestComponent.tsx';

标签: reactjstypescriptwebpack

解决方案


推荐阅读