我有一個由 React 和后端模塊使用的共享模塊。它包含兩個檔案:index.ts和package.json.
包.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 一起使用。我錯過了什么?
uj5u.com熱心網友回復:
檔案名必須是 index.d.ts
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/392984.html
