
NestJS에서 Sequelize를 사용해 모델을 구성 중에 "Error: No default export defined for file or export does not satisfy filename." 에러를 만났다.

의존성 버전
문제가 발생했던 이유는 모델 클래스 이름과 파일 이름이 달라서 발생했던 문제였다.
ProductSaleslocation 모델 클래스는 다음과 같다.
export class ProductSaleslocation extends Model {
이 모델 클래스의 파일 이름은 productSaleslocation.model.ts로 설정했는데, 이 부분이 문제가 되었다.
sequelize-typescript에서 모델은 파일 이름에 매칭된다고 한다. 예를 들어 User 모델이 있다고 하자.
export class User extends Model {}
이 User 모델 클래스를 작성한 파일 이름은 User.ts가 되어야 한다. User.ts 파일은 User 모델과 매치되는 것이다.
클래스 이름과 파일 이름을 매치하지 않고도 문제를 해결하고 싶었는데, default export를 사용하는 방법을 찾을 수 있었다.
먼저 ProductSaleslocation 모델 클래스를 default export로 내보낸다.
export default class ProductSaleslocation extends Model {
모델 클래스를 default import한다.
import ProductSaleslocation from 'src/productsSaleslocations/model/productSaleslocation.model';
모든 모델 클래스에 default export를 적용하고 default import하여 문제를 해결할 수 있었다.
추가적으로 클래스 이름과 파일 이름을 매치하지 않고 named export와 SequelizeModuleOptions의 modelMatch 옵션을 사용하는 방법도 있었다. (참고 링크에서 modelMatch 옵션 확인)