Adonisjs 5.0 TypeError: this.container.singleton is not a function

793 views Asked by At

I just installed the adonis5-scheduler on adonisjs5 and I am getting an error anytime I try to serve

OS: windows 10 node version: 14.6.1 npx version: 6.14.12

Expected result --Build Serve

Actual result

TypeError: this.container.singleton is not a function


1 SchedulerProvider.register
  C:\Users\user\Documents\Code\Sacro\node_modules\adonis5-scheduler\build\providers\SchedulerProvider.js:16

2 anonymous
  C:\Users\user\Documents\Code\Sacro\node_modules\@adonisjs\fold\build\src\Registrar\index.js:103

3 Registrar.register
  C:\Users\user\Documents\Code\Sacro\node_modules\@adonisjs\fold\build\src\Registrar\index.js:101

4 anonymous
  C:\Users\user\Documents\Code\Sacro\node_modules\@adonisjs\application\build\src\Application.js:530

5 Application.registerProviders
  C:\Users\user\Documents\Code\Sacro\node_modules\@adonisjs\application\build\src\Application.js:524

6 HttpServer.wire
  C:\Users\user\Documents\Code\Sacro\node_modules\@adonisjs\core\build\src\Ignitor\HttpServer\index.js:52

7 HttpServer.start
  C:\Users\user\Documents\Code\Sacro\node_modules\@adonisjs\core\build\src\Ignitor\HttpServer\index.js:146

Here is the code in my package.json file as requested in the comment section.

{
  "name": "Sacro",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "node ace build --production",
    "start": "node server.js",
    "dev": "node ace serve --watch",
    "lint": "eslint . --ext=.ts"
  },
  "devDependencies": {
    "@adonisjs/assembler": "^5.2.0",
    "@types/jsdom": "^16.2.10",
    "@types/supertest": "^2.0.11",
    "adonis-preset-ts": "^2.1.0",
    "eslint": "^7.26.0",
    "eslint-plugin-adonis": "^1.3.1",
    "get-port": "^5.1.1",
    "japa": "^3.1.1",
    "jsdom": "^16.5.3",
    "pino-pretty": "^4.8.0",
    "supertest": "^6.1.3",
    "typescript": "^4.2.4",
    "youch": "^2.2.2",
    "youch-terminal": "^1.1.1"
  },
  "dependencies": {
    "@adonisjs/auth": "^5.1.1",
    "@adonisjs/core": "^5.1.6",
    "@adonisjs/lucid": "^10.0.0",
    "@adonisjs/repl": "^3.1.2",
    "adonis5-scheduler": "^1.0.1",
    "adonisjs-paystack": "^0.2.0",
    "axios": "^0.21.1",
    "luxon": "^1.27.0",
    "mysql": "^2.18.1",
    "phc-argon2": "^1.1.1",
    "proxy-addr": "^2.0.6",
    "reflect-metadata": "^0.1.13",
    "source-map-support": "^0.5.19"
  }
}
1

There are 1 answers

0
tomrlh On

In the node_modules/adonis5-scheduler/build/providers/SchedulerProvider, you can make a hotfix:

add a ? after container call to proceed with the evaluation only if container is not null/undefined

[...]this.app.container?.singleton[...] at line 16

[...]this.app.container?.bind[...] at line 21

Important note: I've open an issue reporting this, but I've remember I was using Adonis 5 in it's alpha version.. after creating a brand new latest version Adonis 5 project (npm init adonis-ts-app@latest project-name-here) and installed the adonis5-scheduler, it worked