[英]Why does React not compile my local module with an Interface?
我有一个由 React 和后端模块使用的共享模块。 它包含两个文件: index.ts
和package.json
。
Package.json
{
"name": "app-shared",
"version": "1.0.0",
"license": "ISC"
}
在index.ts
中只有导出的接口,如下所示:
export interface Student extends StudentDto {
ref: any;
id: string;
areAllPaid: boolean;
}
我已经将它安装在我的 React 应用程序中,并且可以导入界面。 但是当我运行 React 应用程序时,会出现以下编译错误:
Failed to compile.
../shared/index.ts 4:7
Module parse failed: Unexpected token (4:7)
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);
|
> export interface Student extends StudentDto {
| ref: any;
| id: string;
此问题与 webpack 有关,但在我的 Git 存储库中没有 webpack 配置文件。 我也在其他模块中使用这个共享模块,它工作正常。
我认为共享模块需要更多代码才能与 Webpack 和 React 一起使用。 我错过了什么?
更新:
当我将文件名更改为index.d.ts
,我得到了不同且可能更好的错误:
Module not found: Can't resolve 'shared' in 'path/path'
有以下两个错误:
index.d.ts
索引.d.ts
declare namespace share {
export interface Student extends StudentDto {
ref: any;
id: string;
areAllPaid: boolean;
}
}
export = share;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.