Skip to content

Latest commit

 

History

History
103 lines (70 loc) · 4.51 KB

known-issues.md

File metadata and controls

103 lines (70 loc) · 4.51 KB
id title
known-issues
Known Issues

Known Issues

Please look here first, to decide if it is a Typegoose or a Mongoose issue.

transpile-only

It is not recommended to run compilers with option transpile-only (like tsc --transpile-only or ts-node --transpile-only), because this will act like not having emitDecoratorMetadata enabled, see Use Without "emitDecoratorMetadata".

tsconfig-paths

TypeScript provides the option to alias paths (with tsconfig-paths) but is somehow incompatible with Typegoose, more info in here.

Self-Containing classes

It is currently not (and probably never) possible to use a self-containing class:

class SomeClass {
  @prop()
  public ref: SomeClass; // ERROR "Maximum Class Stack Size Exceeded"
}

Though Deferred Reference will still work:

class SomeClass {
  @prop({ ref: () => SomeClass }) // or hardcode the string
  public ref: Ref<SomeClass>;
}

Babel

This Section may be outdated

Using babel as a TypeScript compiler is known to cause problems (like incorrect types) (see transpile-only), it is recommended you use tsc, ts-node or ts-jest directly.

If Babel is still needed, then read Babel TypeScript preset and install the following plugins:

:::info emitDecoratorMetadata is not strictly needed, see Use Without emitDecoratorMetadata. :::

module.exports = {
  plugins: [
    ['@babel/plugin-proposal-decorators', { legacy: true }],
    'babel-plugin-transform-typescript-metadata',
    ['@babel/plugin-proposal-class-properties', { loose: true }],
  ]
}

prop on get & set

@prop cannot be applied to get & set (ES6 class keywords), because virtuals do not accept options & schema.loadClass wouldn't load these.

Webpack

Webpack's minimize cannot be used with typegoose, because typegoose relies heavily on reflection and property names.

In webpack, it can be disabled when adding the following to the webpack config:

module.exports = {
  optimization: {
    minimize: false
  }
}

:::note There are some workarounds for some minification problems, like the class name (which would be the model name) can be changed with customName. :::

@types/node breaking change

Early January 2022, there was a update in @types/node, which was actually a breaking change which causes typescript compile errors to show up (like for GridFSBucketWriteStream from mongodb, even though unused).

The current only workaround is to pin the versions of @types/node used to ones before the update, which in the case of typegoose is @types/node@12.20.39.
As of 02-02-2022 (d/m/y), mongoose has released 6.2.0 which upgraded mongodb to a version that has updated types, and typegoose 9.6.0 uses this mongoose version.

NodeJS 17.5 Breaking Change

NodeJS 17.5 was released, which included a breaking change for mongoose, which resulted in a error (/ crash of the application).

Mongoose has released version 6.2.2 on 16.2.22 (d/m/y) which fixes the issue on mongoose's side.
Since 24.2.22 (d/m/y) NodeJS 17.6 is released which should include the fix.

DocumentType is not generic

Typescript has its own DocumentType when having DOM enabled in tsconfig option lib, in any case the correct DocumentType has to be imported directly from typegoose.
It is also recommended to remove the option DOM from the tsconfig option lib when possible.