#Cannot read properties of undefined (reading 'scanForModules')

5 messages · Page 1 of 1 (latest)

cloud perch
#

Hi All,

I recently updated to "@nestjs/core": "^9.2.1" and now I am experiencing an error when using lazyModuleLoader.load in my service.

In my constructor I inject it

@Inject(forwardRef(() => LazyModuleLoader)) private readonly lazyModuleLoader: LazyModuleLoader,

Then in my code:

const { AwsModule, AwsS3Service } = await import('@juicyllama/app-aws')
const awsModule = await this.lazyModuleLoader.load(() => AwsModule)
service = awsModule.get(AwsS3Service)
return await service.create(location, permissions, format, file)

It's throwing this error:

Cannot read properties of undefined (reading 'scanForModules')TypeError: Cannot read properties of undefined (reading 'scanForModules')
    at LazyModuleLoader.load (/Users/andrewslack/Sites/JuicyLlama/@juicyllama/common/node_modules/@nestjs/core/injector/lazy-module-loader/lazy-module-loader.js:16:64)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at StorageService.write

Here is my package.json dependancies

    "peerDependencies": {
        "@juicyllama/utils": "^0.0.13",
        "@nestjs/common": "^9.2.1",
        "@nestjs/jwt": "^9.0.0",
        "@nestjs/passport": "^9.0.0",
        "@nestjs/typeorm": "^9.0.1",
        ...
        "typeorm": "^0.3.11"
    },
    "devDependencies": {
        "@juicyllama/app-aws": "^0.0.3",
        "@nestjs/config": "^2.2.0",
        "@nestjs/core": "^9.2.1",
        "@nestjs/passport": "^9.0.0",
        "@nestjs/platform-express": "^9.2.1",
        "@nestjs/swagger": "^6.1.2",
        "@nestjs/testing": "9.2.1",
       ...
        "typescript": "^4.9.3"
    },

Any help is appreciated

silent wharf
#

Why are you forwardReffing the LazyModuleLoader

cloud perch
#

@silent wharf looks like a red herrin, still showing the same error without it

#

Thats odd, I added LazyModuleLoader as a provider in my module, once I removed that... is started working... I guess there was no need to provide it.