typegoose: Enum not working from other files
Versions
- NodeJS: v12.13.1
- Typegoose(NPM): 6.2.2
- mongoose: 5.8.9
- mongodb: 0.0.0
- nestjs: 6.11.1
What is the Problem?
I can’t use enum prop field
Error: Invalid type used for map!, got: "function Object() { [native code] }" (OrganizationEntity.entityType)
at Object._buildPropMetadata (/.../node_modules/@typegoose/typegoose/src/prop.ts:224:15)
at Object._buildSchema (/.../node_modules/@typegoose/typegoose/src/internal/schema.ts:47:7)
at buildSchema (/.../node_modules/@typegoose/typegoose/src/typegoose.ts:170:9)
at getModelForClass (/.../node_modules/@typegoose/typegoose/src/typegoose.ts:105:58)
......
Code Example
// some-type.enum.ts
export enum SomeType {
Type1 = 'Type 1',
Type2 = 'Type 2',
}
import { SomeType } from './some-type.enum';
export class Item {
@prop({ enum: SomeType })
type?: SomeType;
}
Do you know why it happenes?
The enum is imported from another file when I use enum in the same class file, it’s working!!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 23 (10 by maintainers)
@hasezoey It’s seems nx enable transpile-only option by default
https://github.com/nrwl/nx/issues/2147#issuecomment-609803071
https://github.com/nrwl/nx/blob/670a5f90846bd455ef31b8f5877c6bc697346c27/packages/node/src/utils/config.ts#L43
To solve the issue I have to do this:
@hasezoey I had this same problem in my NestJS server using nestjs-typegoose using NX (which actually doesn’t matter since it uses
ng
commands) which uses Angular CLI which uses webpack to build the project. ChangingTo ( like you pointed out ) works for me
@AliYusuf95 me too facing same issue. waiting for the solution.
This is not working:
But this is working: