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

TypeError: Converting circular structure to JSON #3

Closed
krivochenko opened this issue May 8, 2018 · 6 comments
Closed

TypeError: Converting circular structure to JSON #3

krivochenko opened this issue May 8, 2018 · 6 comments

Comments

@krivochenko
Copy link

Thanks for your work, but I encountered issue:

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at ModuleTokenFactory.getDynamicMetadataToken (C:\www\project\node_modules\@nestjs\core\injector\module-token-factory.js:16:45)
    at ModuleTokenFactory.create (C:\www\project\node_modules\@nestjs\core\injector\module-token-factory.js:10:27)
    at NestContainer.addModule (C:\www\project\node_modules\@nestjs\core\injector\container.js:41:47)
    at DependenciesScanner.storeModule (C:\www\project\node_modules\@nestjs\core\scanner.js:31:24)
    at DependenciesScanner.scanForModules (C:\www\project\node_modules\@nestjs\core\scanner.js:21:14)
    at importedModules.map.innerModule (C:\www\project\node_modules\@nestjs\core\scanner.js:24:18)
    at Array.map (<anonymous>)
    at DependenciesScanner.scanForModules (C:\www\project\node_modules\@nestjs\core\scanner.js:23:25)
    at DependenciesScanner.scan (C:\www\project\node_modules\@nestjs\core\scanner.js:16:14)

Steps for reproducing:

  1. git clone https://github.com/nestjs/typescript-starter.git project
  2. cd project
  3. npm i
  4. npm install --save @nest-modules/mailer
  5. npm install --save nodemailer-mandrill-transport
  6. app.module.ts:
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { MailerModule } from '@nest-modules/mailer';

@Module({
  imports: [
    MailerModule.forRoot(),
  ],
  controllers: [AppController],
  components: [],
})
export class AppModule {}
  1. mailerconfig.ts:
import * as mandrillTransport from 'nodemailer-mandrill-transport';

export = {
  transport: mandrillTransport({
    auth: {
      api_key: 'key'
    }
  }),
  defaults: {
    from:'"nest-mailer" <noreply@nestjs.com>',
  },
  templateDir: './src/common/email-templates'
}

How I can resolve it? Thanks for help.

@cdiaz
Copy link
Member

cdiaz commented May 31, 2018

Hi @krivochenko, It's related with this issue and will be fixed soon, thanks for reporting

@anyx
Copy link

anyx commented Sep 6, 2018

Looks like it wasn't fixed:

const mailerTransport = nodemailer.createTransport({
    sendmail: true,
    newline: 'unix',
    path: '/usr/sbin/sendmail',
});

@Module({
    imports: [
        MailerModule.forRoot({
            transport: mailerTransport,
            defaults: {
                from: config.get('mailer.from'),
            },
            templateDir: './templates/mailer',
        }),
...
$ node index.js
[Nest] 1828   - 2018-9-6 16:20:59   [Application] Converting circular structure to JSON
TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at ModuleTokenFactory.getDynamicMetadataToken (/srv/project/backend/node_modules/@nestjs/core/injector/module-token-factory.js:17:45)
    at ModuleTokenFactory.create (/srv/project/backend/node_modules/@nestjs/core/injector/module-token-factory.js:11:27)
    at ModuleCompiler.compile (/srv/project/backend/node_modules/@nestjs/core/injector/compiler.js:19:47)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:118:7)
    at Function.Module.runMain (module.js:692:11)
    at startup (bootstrap_node.js:194:16)
    at bootstrap_node.js:666:3
 1: node::Abort() [node]
 2: 0x8cea99 [node]
 3: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [node]
 4: 0xb1444c [node]
 5: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 6: 0x154bbd1842fd
Aborted
error Command failed with exit code 134.

nest version: 5.2.0

@RafaelTCostella
Copy link

RafaelTCostella commented Sep 28, 2018

Looks like it wasn't fixed:

const mailerTransport = nodemailer.createTransport({
    sendmail: true,
    newline: 'unix',
    path: '/usr/sbin/sendmail',
});

@Module({
    imports: [
        MailerModule.forRoot({
            transport: mailerTransport,
            defaults: {
                from: config.get('mailer.from'),
            },
            templateDir: './templates/mailer',
        }),
...
$ node index.js
[Nest] 1828   - 2018-9-6 16:20:59   [Application] Converting circular structure to JSON
TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at ModuleTokenFactory.getDynamicMetadataToken (/srv/project/backend/node_modules/@nestjs/core/injector/module-token-factory.js:17:45)
    at ModuleTokenFactory.create (/srv/project/backend/node_modules/@nestjs/core/injector/module-token-factory.js:11:27)
    at ModuleCompiler.compile (/srv/project/backend/node_modules/@nestjs/core/injector/compiler.js:19:47)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:118:7)
    at Function.Module.runMain (module.js:692:11)
    at startup (bootstrap_node.js:194:16)
    at bootstrap_node.js:666:3
 1: node::Abort() [node]
 2: 0x8cea99 [node]
 3: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [node]
 4: 0xb1444c [node]
 5: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 6: 0x154bbd1842fd
Aborted
error Command failed with exit code 134.

nest version: 5.2.0

Hello @anyx! You're making the same mistake that I!

Instead of:

const mailerTransport = nodemailer.createTransport({
    sendmail: true,
    newline: 'unix',
    path: '/usr/sbin/sendmail',
});

@Module({
    imports: [
        MailerModule.forRoot({
            transport: mailerTransport,
            defaults: {
                from: config.get('mailer.from'),
            },
            templateDir: './templates/mailer',
        }),
...

You should do:

const mailerTransport = {
    sendmail: true,
    newline: 'unix',
    path: '/usr/sbin/sendmail',
};

@Module({
    imports: [
        MailerModule.forRoot({
            transport: mailerTransport,
            defaults: {
                from: config.get('mailer.from'),
            },
            templateDir: './templates/mailer',
        }),
...

The reason is that because in this line: https://github.com/nest-modules/mailer/blob/4de893c48fe776398828ea994ca117c5ecb03c57/lib/mailer.provider.ts, mailerProvider already calls createTransport.

@cdiaz I think that we can improve docs with examples for different plugins, if you agree I would like to submit a new PR to that!

@cdiaz
Copy link
Member

cdiaz commented Oct 3, 2018

Hello @RafaelTCostella , your PR will be welcome, feel free to contribute.
Thanks

@RafaelTCostella
Copy link

#8

Done!

@cdiaz cdiaz closed this as completed in 71b218d Oct 5, 2018
@cdiaz
Copy link
Member

cdiaz commented Oct 5, 2018

Solved in v 0.4.1

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

No branches or pull requests

4 participants