Nest: dynamic Modules metadata does not support circular structures

Created on 14 May 2018  路  7Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request

Current behavior

[Nest] 2998   - 2018-5-13 19:41:01   [ExceptionHandler] Converting circular structure to JSON
TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at ModuleTokenFactory.getDynamicMetadataToken (/home/nest/uroboros/node_modules/@nestjs/core/injector/module-token-factory.js:16:45)
    at ModuleTokenFactory.create (/home/nest/uroboros/node_modules/@nestjs/core/injector/module-token-factory.js:10:27)
    at ModuleCompiler.compile (/home/nest/uroboros/node_modules/@nestjs/core/injector/compiler.js:19:47)
    at NestContainer.addModule (/home/nest/uroboros/node_modules/@nestjs/core/injector/container.js:31:70)
    at DependenciesScanner.storeModule (/home/nest/uroboros/node_modules/@nestjs/core/scanner.js:32:24)
    at DependenciesScanner.scanForModules (/home/nest/uroboros/node_modules/@nestjs/core/scanner.js:22:14)
    at modules.map.innerModule (/home/nest/uroboros/node_modules/@nestjs/core/scanner.js:25:18)
    at Array.map (<anonymous>)
    at DependenciesScanner.scanForModules (/home/nest/uroboros/node_modules/@nestjs/core/scanner.js:24:17)

Expected behavior


Nest application successfully started

Minimal reproduction of the problem with instructions

import { DynamicModule, Module } from '@nestjs/common';

@Module({})
export class UroburosModule {

  static forRoot(): DynamicModule {
    let oyra = {bora:{}};
    const UroburosProvider = {
      name: 'UROBUROS_PROVIDER',
      provide: 'UROBUROS_PROVIDER',
      useValue: oyra.bora = oyra
    };

    return {
      module: UroburosModule,
      providers: [UroburosProvider],
      exports: [UroburosProvider]
    };
  }

}

What is the motivation / use case for changing the behavior?


Allow use of external libraries that contain circular references

Environment


Nest version: 5.0.0

For Tooling issues:

  • Node version: 10.0.0
  • Platform: Linux
core type todo 馃挌

All 7 comments

Thanks @cdiaz, I'm on it

Fixed in v5.0.1

Currently trying to upgrade my Nest 4.x.x application to 5.3.10.

My application does have a circular dynamic module and works perfectly fine with 4.x.x, but I'm having the error message TypeError: Converting circular structure to JSON

Looking through your commit history, the commit which fixed this issue is more or less reverted by commit ce498e86150f7de4a260f0c393d47ec4cc920ea1.

Why is this? Can not find any statement on this.

@kamilmysliwiec Please, reopen this issue, Apparently this commit in which changes are reverted, has reopened the problem

Solved by #1142, I'll merge it soon

Published as 5.3.11

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artaommahe picture artaommahe  路  3Comments

cdiaz picture cdiaz  路  3Comments

JulianBiermann picture JulianBiermann  路  3Comments

KamGor picture KamGor  路  3Comments

menme95 picture menme95  路  3Comments