使用 TypeScript 和 NPM 链接创建 React 应用程序:枚举导致模块解析失败

问题描述

我有一个基本的 create-react-app TypeScript 项目 (client)。只是目录,我有一个 server 和一个 shared 文件夹。在 shared 文件夹中,我有许多 interfaceenum,我在 serverclient 之间共享。

我希望将此 shared 文件夹链接到 clientserver 包。

首先,我转到 shared 并运行 $ yarn link,然后从 $ yarn link sharedclient 文件夹运行 server

服务器很高兴,在大多数情况下,客户端也是如此。但是,一旦我使用 enumshared 目录中的 client 之一,我就会收到一个错误:

../shared/src/models/Roles.ts 4:0
Module parse failed: The keyword 'enum' is reserved (4:0)
File was processed with these loaders:
 * ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
You may need an additional loader to handle the result of these loaders.
| $RefreshSetup$(module.id);
| 
> enum Roles {
|     RW_ORG = "rw_org",// can modifiy organization and it's users,nothing else

我是这样导入的: import {Roles} from "shared"; 但也尝试了许多其他方法。

我像这样从 shared index.ts 导出它

import Roles from "./models/Roles";

export type { 
    // all of my interfaces
};
export { Roles }

我所有的 interface 都是可用的,所以我不明白。这到底是怎么回事?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)