首页 > 解决方案 > 使用 ~ 符号导入/导出

问题描述

我有一个组件文件夹,我在其中定义这样的组件:

export const ResultAlert: FunctionComponent<ResultAlertProps> = ({
  severity,
  text,
}) => {
  const classes = useStyles();
  return (
    <Alert className={classes.alert} severity={severity}>
      {' '}
      {text}
    </Alert>
  );
};

在我的组件文件夹中,我制作了一个index.tsx文件,上面写着:

export * from './alerts/ResultAlert';

现在,我需要一种方法来使导入工作如下:

import {ResultAlert} from '~/components';

目前,这给了我一个错误

Cannot find module '~/components' or its corresponding type declarations.

我过去看过这项工作,但我不确定如何。我错过了什么?我是否需要为此设置任何其他框架?

标签: javascriptreactjstypescriptreact-nativebabeljs

解决方案


推荐阅读