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 - Doesn't compile.

See original GitHub issue
  • I’m submitting a … [x] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project

  • Summary Using MongoStore within nestjs crashes the application with the following error:

C:\Users\XapuR\OneDrive\phentix-dashboard\dist\server\main.js:5
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
                                                         ^
TypeError: Cannot read properties of undefined (reading 'create')
    at C:\Users\XapuR\OneDrive\phentix-dashboard\src\server\main.ts:19:25
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\XapuR\OneDrive\phentix-dashboard\dist\server\main.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
import { NestFactory } from '@nestjs/core'
import * as session from 'express-session'
import * as passport from 'passport'
import 'colors'
import { AppModule } from './app.module'
import { computeHash } from '~server/utils/utils'
import MongoStore from 'connect-mongo'
;(async function () {
  const app = await NestFactory.create(AppModule)
  const PORT = process.env.PORT || '3000'
  app.use(
    session({
      secret: computeHash(process.env.COOKIE_SECRET || "we'vebeenreachingyouregardingyourcarsextendedwarranty"),
      cookie: {
        maxAge: 60000 * 60 * 24,
      },
      resave: false,
      saveUninitialized: false,
      store: MongoStore.create({ mongoUrl: process.env.MONGO_URI, touchAfter: 24 * 3600 }),
    })
  )
  app.use(passport.initialize())
  app.use(passport.session())
  await app.listen(PORT, () => console.log(`${'NEST'.blue} ${'|'.gray} ${`Running on port: ${PORT.green}`.white}`.bgBlack))
})()

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
6lph9commented, Dec 4, 2021

Having the same issue here. I have fixed the error by importing it like this:

const MongoStore = require("connect-mongo");

I have no clue if this helps anyone but here you go.

1reaction
LastAprilcommented, Jun 8, 2022

I have the same issue

import { NestFactory } from '@nestjs/core'
import  session from 'express-session'
import  passport from 'passport'
import 'colors'
import { AppModule } from './app.module'
import { computeHash } from '~server/utils/utils'
import MongoStore from 'connect-mongo';

Use esModuleInterop: truie and change your import like above it’ll fix the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nest doesnt want to compile dist correctly · Issue #9298
Nest does not compile the dist folder correctly. I first encountered this problem when nest ... https://github.com/lohevol/nestjs-issue/ ...
Read more >
Nest JS build does does not generate the dist folder
when I execute the npm run build nothing happens. no errors. no dist folder. can any one help me to fix this issue?...
Read more >
Common errors - FAQ | NestJS - A progressive Node.js ...
During your development with NestJS, you may encounter various errors as you learn the framework. "Cannot resolve dependency" error#. Probably the most common ......
Read more >
How to avoid circular dependencies in NestJS
One of the common problems encountered in this regard is circular dependencies. NestJS code will not even compile if there is an unresolved ......
Read more >
nestjs/common
Issues not conforming to the guidelines may be closed immediately. Consulting. With official support, you can get expert help straight from Nest ...
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