nest: TypeError: Map#toJSON isn't generic after Migration to 6

I’m submitting a…


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Receive the following error after migrating my project to 6:

npm start

[nodemon] starting node -r tsconfig-paths/register --inspect=5000 --require ts-node/register src/main.ts Debugger listening on ws://127.0.0.1:5000/084101f0-13b2-451b-a9f5-6eb79abf38a4 For help, see: https://nodejs.org/en/docs/inspector [Nest] 71252 - 03/31/2019, 4:08 PM [NestFactory] Starting Nest application… [Nest] 71252 - 03/31/2019, 4:08 PM [ExceptionHandler] Map#toJSON isn’t generic +3ms TypeError: Map#toJSON isn’t generic at String.toJSON (/Users/me/dev/aqua/aqua-devops/Aqua.pkouame/nestjs/base-server/node_modules/core-js/modules/_collection-to-json.js:6:38) at Function.<anonymous> (/Users/me/dev/aqua/aqua-devops/Aqua.pkouame/nestjs/base-server/node_modules/core-js/modules/_ctx.js:18:15) at JSON.stringify (<anonymous>) at Function.stringify [as default] (/Users/me/dev/aqua/aqua-devops/Aqua.pkouame/nestjs/base-server/node_modules/fast-safe-stringify/index.js:11:18) at ModuleTokenFactory.getDynamicMetadataToken (/Users/me/dev/aqua/aqua-devops/Aqua.pkouame/nestjs/base-server/node_modules/@nestjs/core/injector/module-token-factory.js:20:69) at ModuleTokenFactory.create (/Users/me/dev/aqua/aqua-devops/Aqua.pkouame/nestjs/base-server/node_modules/@nestjs/core/injector/module-token-factory.js:12:27) at ModuleCompiler.compile (/Users/me/dev/aqua/aqua-devops/Aqua.pkouame/nestjs/base-server/node_modules/@nestjs/core/injector/compiler.js:19:47) at process._tickCallback (internal/process/next_tick.js:68:7) at Function.Module.runMain (internal/modules/cjs/loader.js:744:11) at startup (internal/bootstrap/node.js:285:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

Expected behavior

to build and run

Minimal reproduction of the problem with instructions

From a 5.x based project, I upgraded the core nestjs packages to the versions generated in the latest CLI nest new app (after upgrading to the latest nest-cli)

I also get the same error after a more comprehensive yarn upgrade --latest

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

Environment


Nest version: ^6.0.0

 
For Tooling issues:
- Node version: 10.13.0  
- Platform:  
Mac
Others:

contents of my package.json:

`{
  "name": "base-server",
  "version": "0.0.1",
  "description": "base server",
  "author": "pak",
  "license": "MIT",
  "scripts": {
    "build": "tsc -p tsconfig.build.json",
    "format": "prettier --write \"src/**/*.ts\"",
    "start": "ts-node -r tsconfig-paths/register src/main.ts",
    "start:dev": "nodemon",
    "start:debug": "nodemon --config nodemon-debug.json",
    "prestart:prod": "rimraf dist && npm run build",
    "start:prod": "node dist/main.js",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/common": "^6.0.0",
    "@nestjs/core": "^6.0.0",
    "@nestjs/mongoose": "^6.0.0",
    "@nestjs/passport": "^6.0.0",
    "@nestjs/platform-express": "^6.0.0",
    "@nestjs/swagger": "^3.0.2",
    "automapper-ts": "^1.9.0",
    "babel-polyfill": "^6.26.0",
    "bcryptjs": "^2.4.3",
    "config": "^3.0.1",
    "devextreme": "^18.2.7",
    "devextreme-query-mongodb": "^2.0.6",
    "faker": "^4.1.0",
    "jsonwebtoken": "^8.4.0",
    "lodash": "^4.17.11",
    "mongoose": "^5.4.13",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "reflect-metadata": "^0.1.12",
    "rimraf": "^2.6.2",
    "rxjs": "^6.3.3",
    "typegoose": "^5.5.0",
    "typescript": "^3.0.1"
  },
  "devDependencies": {
    "@nestjs/testing": "^6.0.0",
    "@types/bcryptjs": "^2.4.2",
    "@types/config": "^0.0.34",
    "@types/express": "^4.16.0",
    "@types/faker": "^4.1.5",
    "@types/jest": "^23.3.13",
    "@types/jsonwebtoken": "^8.3.0",
    "@types/lodash": "^4.14.121",
    "@types/mongoose": "^5.3.17",
    "@types/node": "^10.12.18",
    "@types/passport": "^1.0.0",
    "@types/passport-jwt": "^3.0.1",
    "@types/supertest": "^2.0.7",
    "eslint": "^5.15.3",
    "jest": "^23.6.0",
    "nodemon": "^1.18.9",
    "prettier": "^1.15.3",
    "supertest": "^3.4.1",
    "ts-jest": "^23.10.5",
    "ts-loader": "^4.4.2",
    "ts-node": "^7.0.1",
    "tsconfig-paths": "^3.7.0",
    "tslint": "5.12.1",
    "typescript": "^3.2.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}`

Contents of main.ts:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
// import { HttpExceptionFilter } from './shared/filters/http-exception.filter';

declare const module: any;

async function bootstrap() {
    // Define some CORS Options to enable CORS support cross-domain security
    const corsOptions = {
        origin: '*',
        methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
        allowedHeaders: ['Content-Type', 'Authorization'],
        exposedHeaders: ['Content-Type', 'Authorization', 'Content-Range', 'X-Content-Range'],
        preflightContinue: false,
        optionsSuccessStatus: 204,
    };
    // You can pass a corsOptions object like this here...or as part of the enableCors() call below
    const app = await NestFactory.create(AppModule, {cors: true});
    // const app = await NestFactory.create(AppModule);
    const hostDomain = AppModule.isDev ? `${AppModule.host}:${AppModule.port}` : AppModule.host;

    const swaggerOptions = new DocumentBuilder()
        .setTitle('Nest MEAN')
        .setDescription('API Documentation')
        .setVersion('1.0.0')
        .setHost(hostDomain.split('//')[1])
        .setSchemes(AppModule.isDev ? 'http' : 'https')
        .setBasePath('/api')
        .addBearerAuth('Authorization', 'header')
        .build();

    const swaggerDoc = SwaggerModule.createDocument(app, swaggerOptions);

    SwaggerModule.setup('/api/docs', app, swaggerDoc, {
        swaggerUrl: `${hostDomain}/api/docs-json`,
        explorer: true,
        swaggerOptions: {
            docExpansion: 'list',
            filter: true,
            showRequestDuration: true,
        },
    });

    if (module.hot) {
        module.hot.accept();
        module.hot.dispose(() => app.close());
    }

    app.setGlobalPrefix('api');
    // app.useGlobalFilters(new HttpExceptionFilter());

    // Enable CORS and pass in our options here...unecessary if this was already enabled during the factory
    // setup above...
    // app.enableCors(corsOptions);

    await app.listen(AppModule.port);
}

bootstrap();

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Replacing babel-polyfill with @babel/polyfill in my webpack config fixed this for me.