Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using type enum from third party imported npm package causes "is not defined by 'exports'" #2087

Closed
2 of 4 tasks
tobias-jueschke opened this issue Sep 16, 2022 · 9 comments
Closed
2 of 4 tasks

Comments

@tobias-jueschke
Copy link

tobias-jueschke commented Sep 16, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I have a simple nestjs dto class importing an enum type from a third party npm package.

import { OrderStatus } from '@company/common';

export class OrderListItemDto {
  @IsEnum(OrderStatus)
  @IsNotEmpty()
  public status: OrderStatus;
}

In the @company/common modul the enum is exported as follows:

export enum OrderStatus {
  NEW = "new",
}

running the app cause the following error:

Error: Package subpath './dist/enums/order-status.enum' is not defined by "exports" in /home/user/data/oms-order-service/node_modules/@company/common/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:453:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:729:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Function._OPENAPI_METADATA_FACTORY (/home/user/data/oms-order-service/dist/orders/dtos/order-list-item.dto.js:20:202)

If I change the type of the property to stringand keep the import the app start successfully. If I use the enum not in *.dto files the enum works fine.

Steps to reproduce

https://stackblitz.com/edit/nestjs-typescript-starter-bbgorc?file=package.json,src%2Fmain.ts,nest-cli.json,src%2Fdtos%2Fcats.dto.ts,src%2Fapp.controller.ts,src%2Fapp.service.ts

Expected behavior

APP runs with imported enum from third party npm package.

Package version

6.0.5

NestJS version

9.0.9

Node.js version

16.14.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@tobias-jueschke
Copy link
Author

I found out that the nestjs/swagger cli plugin causes the problem. If I remove the plugin it works as expected.

@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

@aqemi
Copy link

aqemi commented Feb 10, 2023

Having the same issue
Looks like nest js swagger plugin creates code in a compiled bundle like "require("package/internal")"

@gradam
Copy link

gradam commented Sep 20, 2023

Im experiencing the same issue when using monorepo and importing DTOs from shared packages.

For the DTOs i found a workaround.

instead

import { barDto } from '@shared/dtos'

export class fooDto {
  bar: barDto;
}

you can create new empty class in your app and just extend from original DTO

import { barDto as barDtoExternal } from '@shared/dtos'

class barDto extends barDtoExternal {}

export class fooDto {
  bar: barDto;
}

@DavidReinberger
Copy link

Did anyone solved this issue? I'm having the same problem with shared enums...

@bibitoo
Copy link

bibitoo commented May 22, 2024

I also encountered similar problem, im my case the package path is absolute path. I move the project to a none unicode character path and it work.

@icco
Copy link

icco commented Jun 20, 2024

https://stackblitz.com/edit/nestjs-typescript-starter-bbgorc?file=package.json,src%2Fmain.ts,nest-cli.json,src%2Fdtos%2Fcats.dto.ts,src%2Fapp.controller.ts,src%2Fapp.service.ts

@kamilmysliwiec the description has a stackblitz and this is still an issue.

@kamilmysliwiec
Copy link
Member

Let's track this here #3029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants