Home > front end >  Why does React not compile my local module with an Interface?
Why does React not compile my local module with an Interface?

Time:12-22

I have a shared module which is used by an React and Backend module. It contains two files: index.ts and package.json.

Package.json

{
  "name": "app-shared",
  "version": "1.0.0",
  "license": "ISC"
}

In index.ts there are just exported interfaces like the following one:

export interface Student extends StudentDto {
    ref: any;
    id: string;
    areAllPaid: boolean;
}

I have installed it in my React app and can import the interface. But when I run the React app it get the following compilation error:

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;

This issue is related to webpack but nowhere in my Git repo is webpack config file. I use this shared module also in other modules and it works fine.

I think that shared module need some more code in order to work with Webpack and React. What did I miss?

CodePudding user response:

The filename must be index.d.ts

  • Related