question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@nestjs/swagger and bson lib collision problem

See original GitHub issue

I’m submitting a Bug report


[ ] 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.
import { PrimaryKey, Property, SerializedPrimaryKey } from '@mikro-orm/core';

import { ObjectId } from 'bson';

export abstract class CommonEntity {
  @PrimaryKey()
  _id: ObjectId;

  @SerializedPrimaryKey()
  id!: string; // string variant of PK, will be handled automatically

  @Property()
  createdAt = new Date();

  @Property({ onUpdate: () => new Date() })
  updatedAt = new Date();
}

{
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "projects": {},
  "compilerOptions": {
    "webpack": false,
    "plugins": [
      {
        "name": "@nestjs/swagger",
        "options": {
          "classValidatorShim": true,
          "introspectComments": true
        }
      }
    ]
  }
}

Current behavior

Error: Cannot find module ‘bson/bson’ Require stack:

  • /Volumes/HD/workspace/_temp/hello-nest/dist/src/entities/common.entity.js
  • /Volumes/HD/workspace/_temp/hello-nest/dist/src/modules/users/entities/user.entity.js
  • /Volumes/HD/workspace/_temp/hello-nest/dist/src/modules/users/users.service.js
  • /Volumes/HD/workspace/_temp/hello-nest/dist/src/modules/users/users.module.js
  • /Volumes/HD/workspace/_temp/hello-nest/dist/src/app.module.js
  • /Volumes/HD/workspace/_temp/hello-nest/dist/src/main.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15)

Expected behavior

Expected import bson,dont bson/bson

Minimal reproduction of the problem with instructions

https://github.com/WumaCoder/hello-nest/blob/a27ab9a6eb82d99890a6a2ce56ca2e71057579b9/src/entities/common.entity.ts

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

npm i npm run start

Environment


Nest version: 8.0

 
For Tooling issues:
- Node version: node 16  
- Platform:  mac 15

Others:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shwaddell28commented, Dec 21, 2022

This appears to be an issue with the CLI Plugin. I was able to solve this issue by removing the @nestjs/swagger plugin declaration from the nest-cli.json file. We have declared decorators manually so the plugin was not needed. As soon as it was removed, this problem went away.

1reaction
rubiincommented, Nov 7, 2022

Did you run mongodb instance locally? Without that the orm wont bootup You can see here the logs https://imgur.com/a/K7VbNCL @micalevisk

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI (Swagger) | NestJS - A progressive Node.js framework
Hint To generate and download a Swagger JSON file, navigate to ... there may be a problem with CSP, to solve this collision,...
Read more >
Nest + Swagger not recognizing endpoints or parameters
Ultimately I think the issue is: Swagger + Nest is not creating unique operationId 's for each method. My understanding is that methods...
Read more >
Multiple messages for the same http status code not displayed.
I was able to generate swagger API documentation for my restful services that use Jboss and resteasy. The only issue i am facing...
Read more >
NestJS — The Hero We Didn't Know We Needed - SingleStone
One problem with our Swagger UI docs is that it does not define enough of our endpoints. If you scaffold another feature it...
Read more >
Publishing NestJS Packages with npm - DEV Community ‍ ‍
Hello first great the article just a question after following the steps install @ nestjs / swagger, but it gives me an error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found